Comply with noImplicitAny (#9940)

* Stash noImplicitAny work

* Stash

* Fix imports

* Iterate

* Fix tests

* Delint

* Fix tests
This commit is contained in:
Michael Telatynski
2023-02-13 11:39:16 +00:00
committed by GitHub
parent ac7f69216e
commit 61a63e47f4
359 changed files with 1621 additions and 1353 deletions

View File

@@ -18,7 +18,7 @@ limitations under the License.
*/
import url from "url";
import React, { ContextType, createRef, MutableRefObject, ReactNode } from "react";
import React, { ContextType, createRef, CSSProperties, MutableRefObject, ReactNode } from "react";
import classNames from "classnames";
import { MatrixCapabilities } from "matrix-widget-api";
import { Room, RoomEvent } from "matrix-js-sdk/src/models/room";
@@ -81,7 +81,7 @@ interface IProps {
// Is this an instance of a user widget
userWidget: boolean;
// sets the pointer-events property on the iframe
pointerEvents?: string;
pointerEvents?: CSSProperties["pointerEvents"];
widgetPageTitle?: string;
showLayoutButtons?: boolean;
// Handle to manually notify the PersistedElement that it needs to move
@@ -562,9 +562,9 @@ export default class AppTile extends React.Component<IProps, IState> {
"microphone; camera; encrypted-media; autoplay; display-capture; clipboard-write; " + "clipboard-read;";
const appTileBodyClass = "mx_AppTileBody" + (this.props.miniMode ? "_mini " : " ");
const appTileBodyStyles = {};
const appTileBodyStyles: CSSProperties = {};
if (this.props.pointerEvents) {
appTileBodyStyles["pointerEvents"] = this.props.pointerEvents;
appTileBodyStyles.pointerEvents = this.props.pointerEvents;
}
const loadingElement = (

View File

@@ -373,7 +373,7 @@ export default class Dropdown extends React.Component<DropdownProps, IState> {
);
}
const dropdownClasses = {
const dropdownClasses: Record<string, boolean> = {
mx_Dropdown: true,
mx_Dropdown_disabled: this.props.disabled,
};

View File

@@ -14,11 +14,11 @@ See the License for the specific language governing permissions and
limitations under the License.
*/
import React from "react";
import React, { ChangeEvent } from "react";
import { _t } from "../../../languageHandler";
import Field from "./Field";
import AccessibleButton from "./AccessibleButton";
import AccessibleButton, { ButtonEvent } from "./AccessibleButton";
interface IItemProps {
index?: number;
@@ -35,21 +35,21 @@ export class EditableItem extends React.Component<IItemProps, IItemState> {
verifyRemove: false,
};
private onRemove = (e): void => {
private onRemove = (e: ButtonEvent): void => {
e.stopPropagation();
e.preventDefault();
this.setState({ verifyRemove: true });
};
private onDontRemove = (e): void => {
private onDontRemove = (e: ButtonEvent): void => {
e.stopPropagation();
e.preventDefault();
this.setState({ verifyRemove: false });
};
private onActuallyRemove = (e): void => {
private onActuallyRemove = (e: ButtonEvent): void => {
e.stopPropagation();
e.preventDefault();
@@ -105,19 +105,19 @@ interface IProps {
}
export default class EditableItemList<P = {}> extends React.PureComponent<IProps & P> {
protected onItemAdded = (e): void => {
protected onItemAdded = (e: ButtonEvent): void => {
e.stopPropagation();
e.preventDefault();
if (this.props.onItemAdded) this.props.onItemAdded(this.props.newItem);
this.props.onItemAdded?.(this.props.newItem);
};
protected onItemRemoved = (index: number): void => {
if (this.props.onItemRemoved) this.props.onItemRemoved(index);
this.props.onItemRemoved?.(index);
};
protected onNewItemChanged = (e): void => {
if (this.props.onNewItemChanged) this.props.onNewItemChanged(e.target.value);
protected onNewItemChanged = (e: ChangeEvent<HTMLInputElement>): void => {
this.props.onNewItemChanged?.(e.target.value);
};
protected renderNewItemField(): JSX.Element {

View File

@@ -32,13 +32,13 @@ const EffectsOverlay: FunctionComponent<IProps> = ({ roomWidth }) => {
const lazyLoadEffectModule = async (name: string): Promise<ICanvasEffect> => {
if (!name) return null;
let effect: ICanvasEffect | null = effectsRef.current[name] || null;
let effect: ICanvasEffect | null = effectsRef.current.get(name) || null;
if (effect === null) {
const options = CHAT_EFFECTS.find((e) => e.command === name)?.options;
try {
const { default: Effect } = await import(`../../../effects/${name}`);
effect = new Effect(options);
effectsRef.current[name] = effect;
effectsRef.current.set(name, effect);
} catch (err) {
logger.warn(`Unable to load effect module at '../../../effects/${name}.`, err);
}
@@ -70,7 +70,7 @@ const EffectsOverlay: FunctionComponent<IProps> = ({ roomWidth }) => {
// eslint-disable-next-line react-hooks/exhaustive-deps
const currentEffects = effectsRef.current; // this is not a react node ref, warning can be safely ignored
for (const effect in currentEffects) {
const effectModule: ICanvasEffect = currentEffects[effect];
const effectModule: ICanvasEffect = currentEffects.get(effect);
if (effectModule && effectModule.isRunning) {
effectModule.stop();
}

View File

@@ -34,7 +34,7 @@ interface IState {
* catch exceptions during rendering in the component tree below them.
*/
export default class ErrorBoundary extends React.PureComponent<{}, IState> {
public constructor(props) {
public constructor(props: {}) {
super(props);
this.state = {

View File

@@ -16,7 +16,7 @@ See the License for the specific language governing permissions and
limitations under the License.
*/
import React, { ComponentProps } from "react";
import React, { ComponentProps, ReactNode } from "react";
import { MatrixEvent } from "matrix-js-sdk/src/models/event";
import { RoomMember } from "matrix-js-sdk/src/models/room-member";
import { EventType } from "matrix-js-sdk/src/@types/event";
@@ -161,7 +161,15 @@ export default class EventListSummary extends React.Component<IProps> {
* @returns {string[]} an array of transitions.
*/
private static getCanonicalTransitions(transitions: TransitionType[]): TransitionType[] {
const modMap = {
const modMap: Partial<
Record<
TransitionType,
{
after: TransitionType;
newTransition: TransitionType;
}
>
> = {
[TransitionType.Joined]: {
after: TransitionType.Left,
newTransition: TransitionType.JoinedAndLeft,
@@ -170,10 +178,6 @@ export default class EventListSummary extends React.Component<IProps> {
after: TransitionType.Joined,
newTransition: TransitionType.LeftAndJoined,
},
// $currentTransition : {
// 'after' : $nextTransition,
// 'newTransition' : 'new_transition_type',
// },
};
const res: TransitionType[] = [];
@@ -237,15 +241,11 @@ export default class EventListSummary extends React.Component<IProps> {
* @param {number} repeats the number of times the transition was repeated in a row.
* @returns {string} the written Human Readable equivalent of the transition.
*/
private static getDescriptionForTransition(
t: TransitionType,
userCount: number,
count: number,
): string | JSX.Element {
private static getDescriptionForTransition(t: TransitionType, userCount: number, count: number): ReactNode | null {
// The empty interpolations 'severalUsers' and 'oneUser'
// are there only to show translators to non-English languages
// that the verb is conjugated to plural or singular Subject.
let res = null;
let res: ReactNode | undefined;
switch (t) {
case TransitionType.Joined:
res =
@@ -377,7 +377,7 @@ export default class EventListSummary extends React.Component<IProps> {
break;
}
return res;
return res ?? null;
}
private static getTransitionSequence(events: IUserEvents[]): TransitionType[] {

View File

@@ -145,7 +145,7 @@ export default class Field extends React.PureComponent<PropShapes, IState> {
});
}, VALIDATION_THROTTLE_MS);
public constructor(props) {
public constructor(props: PropShapes) {
super(props);
this.state = {
valid: undefined,
@@ -165,7 +165,7 @@ export default class Field extends React.PureComponent<PropShapes, IState> {
});
}
private onFocus = (ev): void => {
private onFocus = (ev: React.FocusEvent<any>): void => {
this.setState({
focused: true,
});
@@ -175,22 +175,18 @@ export default class Field extends React.PureComponent<PropShapes, IState> {
});
}
// Parent component may have supplied its own `onFocus` as well
if (this.props.onFocus) {
this.props.onFocus(ev);
}
this.props.onFocus?.(ev);
};
private onChange = (ev): void => {
private onChange = (ev: React.ChangeEvent<any>): void => {
if (this.props.validateOnChange) {
this.validateOnChange();
}
// Parent component may have supplied its own `onChange` as well
if (this.props.onChange) {
this.props.onChange(ev);
}
this.props.onChange?.(ev);
};
private onBlur = (ev): void => {
private onBlur = (ev: React.FocusEvent<any>): void => {
this.setState({
focused: false,
});
@@ -200,9 +196,7 @@ export default class Field extends React.PureComponent<PropShapes, IState> {
});
}
// Parent component may have supplied its own `onBlur` as well
if (this.props.onBlur) {
this.props.onBlur(ev);
}
this.props.onBlur?.(ev);
};
public async validate({ focused, allowEmpty = true }: IValidateOpts): Promise<boolean> {

View File

@@ -91,7 +91,7 @@ interface IState {
}
export default class ImageView extends React.Component<IProps, IState> {
public constructor(props) {
public constructor(props: IProps) {
super(props);
const { thumbnailInfo } = this.props;

View File

@@ -308,8 +308,8 @@ export default class InteractiveTooltip extends React.Component<IProps, IState>
side: Direction.Top,
};
public constructor(props, context) {
super(props, context);
public constructor(props: IProps) {
super(props);
this.state = {
contentRect: null,

View File

@@ -30,7 +30,7 @@ interface IState {
}
export default class InviteReason extends React.PureComponent<IProps, IState> {
public constructor(props) {
public constructor(props: IProps) {
super(props);
this.state = {
// We hide the reason for invitation by default, since it can be a

View File

@@ -22,22 +22,24 @@ import { Caption } from "../typography/Caption";
interface IProps {
// The value for the toggle switch
value: boolean;
"value": boolean;
// The translated label for the switch
label: string;
"label": string;
// The translated caption for the switch
caption?: string;
"caption"?: string;
// Tooltip to display
tooltip?: string;
"tooltip"?: string;
// Whether or not to disable the toggle switch
disabled?: boolean;
"disabled"?: boolean;
// True to put the toggle in front of the label
// Default false.
toggleInFront?: boolean;
"toggleInFront"?: boolean;
// Additional class names to append to the switch. Optional.
className?: string;
"className"?: string;
// The function to call when the value changes
onChange(checked: boolean): void;
"data-testid"?: string;
}
export default class LabelledToggleSwitch extends React.PureComponent<IProps> {

View File

@@ -32,7 +32,7 @@ export default class Measured extends React.PureComponent<IProps> {
breakpoint: 500,
};
public constructor(props) {
public constructor(props: IProps) {
super(props);
this.instanceId = Measured.instanceCount++;

View File

@@ -15,7 +15,7 @@ See the License for the specific language governing permissions and
limitations under the License.
*/
import React, { ContextType, MutableRefObject } from "react";
import React, { ContextType, CSSProperties, MutableRefObject } from "react";
import { Room } from "matrix-js-sdk/src/models/room";
import WidgetUtils from "../../../utils/WidgetUtils";
@@ -26,7 +26,7 @@ import MatrixClientContext from "../../../contexts/MatrixClientContext";
interface IProps {
persistentWidgetId: string;
persistentRoomId: string;
pointerEvents?: string;
pointerEvents?: CSSProperties["pointerEvents"];
movePersistedElement: MutableRefObject<(() => void) | undefined>;
}

View File

@@ -20,6 +20,7 @@ import { Room } from "matrix-js-sdk/src/models/room";
import { RoomMember } from "matrix-js-sdk/src/models/room-member";
import { logger } from "matrix-js-sdk/src/logger";
import { MatrixClient } from "matrix-js-sdk/src/client";
import { MatrixEvent } from "matrix-js-sdk/src/models/event";
import dis from "../../../dispatcher/dispatcher";
import { MatrixClientPeg } from "../../../MatrixClientPeg";
@@ -30,6 +31,7 @@ import Tooltip, { Alignment } from "./Tooltip";
import RoomAvatar from "../avatars/RoomAvatar";
import MemberAvatar from "../avatars/MemberAvatar";
import { objectHasDiff } from "../../../utils/objects";
import { ButtonEvent } from "./AccessibleButton";
export enum PillType {
UserMention = "TYPE_USER_MENTION",
@@ -180,7 +182,7 @@ export default class Pill extends React.Component<IProps, IState> {
});
};
private doProfileLookup(userId: string, member): void {
private doProfileLookup(userId: string, member: RoomMember): void {
MatrixClientPeg.get()
.getProfileInfo(userId)
.then((resp) => {
@@ -196,7 +198,7 @@ export default class Pill extends React.Component<IProps, IState> {
getDirectionalContent: function () {
return this.getContent();
},
};
} as MatrixEvent;
this.setState({ member });
})
.catch((err) => {
@@ -204,7 +206,7 @@ export default class Pill extends React.Component<IProps, IState> {
});
}
private onUserPillClicked = (e): void => {
private onUserPillClicked = (e: ButtonEvent): void => {
e.preventDefault();
dis.dispatch({
action: Action.ViewUser,

View File

@@ -44,7 +44,7 @@ export default class RoomAliasField extends React.PureComponent<IProps, IState>
private fieldRef = createRef<Field>();
public constructor(props, context) {
public constructor(props: IProps, context: React.ContextType<typeof MatrixClientContext>) {
super(props, context);
this.state = {

View File

@@ -42,7 +42,7 @@ const RoomFacePile: FC<IProps> = ({ room, onlyKnownUsers = true, numShown = DEFA
const count = members.length;
// sort users with an explicit avatar first
const iteratees = [(member) => (member.getMxcAvatarUrl() ? 0 : 1)];
const iteratees = [(member: RoomMember) => (member.getMxcAvatarUrl() ? 0 : 1)];
if (onlyKnownUsers) {
members = members.filter(isKnownMember);
} else {

View File

@@ -23,7 +23,7 @@ import SdkConfig from "../../../SdkConfig";
import dis from "../../../dispatcher/dispatcher";
import { Action } from "../../../dispatcher/actions";
import { UserTab } from "../dialogs/UserTab";
import AccessibleButton from "./AccessibleButton";
import AccessibleButton, { ButtonEvent } from "./AccessibleButton";
export enum WarningKind {
Files,
@@ -49,7 +49,7 @@ export default function SearchWarning({ isRoomEncrypted, kind }: IProps): JSX.El
a: (sub) => (
<AccessibleButton
kind="link_inline"
onClick={(evt) => {
onClick={(evt: ButtonEvent) => {
evt.preventDefault();
dis.dispatch({
action: Action.ViewUserSettings,

View File

@@ -33,7 +33,7 @@ function languageMatchesSearchQuery(query: string, language: Languages[0]): bool
interface SpellCheckLanguagesDropdownIProps {
className: string;
value: string;
onOptionChange(language: string);
onOptionChange(language: string): void;
}
interface SpellCheckLanguagesDropdownIState {
@@ -45,7 +45,7 @@ export default class SpellCheckLanguagesDropdown extends React.Component<
SpellCheckLanguagesDropdownIProps,
SpellCheckLanguagesDropdownIState
> {
public constructor(props) {
public constructor(props: SpellCheckLanguagesDropdownIProps) {
super(props);
this.onSearchChange = this.onSearchChange.bind(this);

View File

@@ -14,7 +14,7 @@ See the License for the specific language governing permissions and
limitations under the License.
*/
import React, { ReactNode } from "react";
import React, { ChangeEvent, ReactNode } from "react";
import classNames from "classnames";
import StyledRadioButton from "./StyledRadioButton";
@@ -47,8 +47,8 @@ function StyledRadioGroup<T extends string>({
disabled,
onChange,
}: IProps<T>): JSX.Element {
const _onChange = (e): void => {
onChange(e.target.value);
const _onChange = (e: ChangeEvent<HTMLInputElement>): void => {
onChange(e.target.value as T);
};
return (

View File

@@ -68,7 +68,7 @@ export default class Tooltip extends React.PureComponent<ITooltipProps, State> {
alignment: Alignment.Natural,
};
public constructor(props) {
public constructor(props: ITooltipProps) {
super(props);
this.state = {};
@@ -92,7 +92,7 @@ export default class Tooltip extends React.PureComponent<ITooltipProps, State> {
this.updatePosition();
}
public componentDidUpdate(prevProps): void {
public componentDidUpdate(prevProps: ITooltipProps): void {
if (objectHasDiff(prevProps, this.props)) {
this.updatePosition();
}

View File

@@ -24,7 +24,7 @@ interface IProps {
}
export default class TooltipButton extends React.Component<IProps> {
public constructor(props) {
public constructor(props: IProps) {
super(props);
}

View File

@@ -40,7 +40,7 @@ interface IProps {
export default class TruncatedList extends React.Component<IProps> {
public static defaultProps = {
truncateAt: 2,
createOverflowElement(overflowCount, totalCount) {
createOverflowElement(overflowCount: number, totalCount: number) {
return <div>{_t("And %(count)s more...", { count: overflowCount })}</div>;
},
};