Skip to content
This repository has been archived by the owner on Sep 11, 2024. It is now read-only.

Commit

Permalink
Typescript updates (#9658)
Browse files Browse the repository at this point in the history
* Typescript updates

* Update @types/node

* Fix more types
  • Loading branch information
t3chguy authored Nov 30, 2022
1 parent baaa9f5 commit d258402
Show file tree
Hide file tree
Showing 59 changed files with 86 additions and 90 deletions.
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@
"@types/katex": "^0.14.0",
"@types/lodash": "^4.14.168",
"@types/modernizr": "^3.5.3",
"@types/node": "^14.18.28",
"@types/node": "^16",
"@types/pako": "^1.0.1",
"@types/parse5": "^6.0.0",
"@types/qrcode": "^1.3.5",
Expand Down Expand Up @@ -212,7 +212,7 @@
"stylelint": "^14.9.1",
"stylelint-config-standard": "^26.0.0",
"stylelint-scss": "^4.2.0",
"typescript": "4.8.4",
"typescript": "4.9.3",
"walk": "^2.3.14"
},
"jest": {
Expand Down
4 changes: 0 additions & 4 deletions src/@types/global.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -149,14 +149,10 @@ declare global {

// https://developer.mozilla.org/en-US/docs/Web/API/OffscreenCanvas
interface OffscreenCanvas {
height: number;
width: number;
getContext: HTMLCanvasElement["getContext"];
convertToBlob(opts?: {
type?: string;
quality?: number;
}): Promise<Blob>;
transferToImageBitmap(): ImageBitmap;
}

interface HTMLAudioElement {
Expand Down
4 changes: 2 additions & 2 deletions src/DecryptionFailureTracker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -174,12 +174,12 @@ export class DecryptionFailureTracker {
* Start checking for and tracking failures.
*/
public start(): void {
this.checkInterval = setInterval(
this.checkInterval = window.setInterval(
() => this.checkFailures(Date.now()),
DecryptionFailureTracker.CHECK_INTERVAL_MS,
);

this.trackInterval = setInterval(
this.trackInterval = window.setInterval(
() => this.trackFailures(),
DecryptionFailureTracker.TRACK_INTERVAL_MS,
);
Expand Down
2 changes: 1 addition & 1 deletion src/LegacyCallHandler.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,7 @@ export default class LegacyCallHandler extends EventEmitter {
logger.log("Failed to check for protocol support and no retries remain: assuming no support", e);
} else {
logger.log("Failed to check for protocol support: will retry", e);
setTimeout(() => {
window.setTimeout(() => {
this.checkProtocols(maxTries - 1);
}, 10000);
}
Expand Down
4 changes: 2 additions & 2 deletions src/Lifecycle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -584,7 +584,7 @@ async function doSetLoggedIn(
// later than MatrixChat might assume.
//
// we fire it *synchronously* to make sure it fires before on_logged_in.
// (dis.dispatch uses `setTimeout`, which does not guarantee ordering.)
// (dis.dispatch uses `window.setTimeout`, which does not guarantee ordering.)
dis.dispatch({ action: 'on_logging_in' }, true);

if (clearStorageEnabled) {
Expand Down Expand Up @@ -865,7 +865,7 @@ export async function onLoggedOut(): Promise<void> {
if (SdkConfig.get().logout_redirect_url) {
logger.log("Redirecting to external provider to finish logout");
// XXX: Defer this so that it doesn't race with MatrixChat unmounting the world by going to /#/login
setTimeout(() => {
window.setTimeout(() => {
window.location.href = SdkConfig.get().logout_redirect_url;
}, 100);
}
Expand Down
2 changes: 1 addition & 1 deletion src/NodeAnimator.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ export default class NodeAnimator extends React.Component<IProps> {
}

// and then we animate to the resting state
setTimeout(() => {
window.setTimeout(() => {
this.applyStyles(domNode as HTMLElement, restingStyle);
}, 0);
}
Expand Down
2 changes: 1 addition & 1 deletion src/PasswordReset.ts
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ export default class PasswordReset {
this.checkEmailLinkClicked()
.then(() => resolve())
.catch(() => {
setTimeout(
window.setTimeout(
() => this.tryCheckEmailLinkClicked(resolve),
CHECK_EMAIL_VERIFIED_POLL_INTERVAL,
);
Expand Down
2 changes: 1 addition & 1 deletion src/audio/PlaybackClock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ export class PlaybackClock implements IDestroyable {
// cast to number because the types are wrong
// 100ms interval to make sure the time is as accurate as possible without
// being overly insane
this.timerId = <number><any>setInterval(this.checkTime, 100);
this.timerId = <number><any>window.setInterval(this.checkTime, 100);
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/autocomplete/Autocompleter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ export interface ISelectionRange {
}

export interface ICompletion {
type: "at-room" | "command" | "community" | "room" | "user";
type?: "at-room" | "command" | "community" | "room" | "user";
completion: string;
completionId?: string;
component?: ReactElement;
Expand Down
10 changes: 5 additions & 5 deletions src/autocomplete/EmojiProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ export default class EmojiProvider extends AutocompleteProvider {
return []; // don't give any suggestions if the user doesn't want them
}

let completions = [];
let completions: ISortedEmoji[] = [];
const { command, range } = this.getCurrentCommand(query, selection);

if (command && command[0].length > 2) {
Expand Down Expand Up @@ -132,7 +132,7 @@ export default class EmojiProvider extends AutocompleteProvider {
}
// Finally, sort by original ordering
sorters.push(c => c._orderBy);
completions = sortBy(uniq(completions), sorters);
completions = sortBy<ISortedEmoji>(uniq(completions), sorters);

completions = completions.slice(0, LIMIT);

Expand All @@ -141,9 +141,9 @@ export default class EmojiProvider extends AutocompleteProvider {
this.recentlyUsed.forEach(emoji => {
sorters.push(c => score(emoji.shortcodes[0], c.emoji.shortcodes[0]));
});
completions = sortBy(uniq(completions), sorters);
completions = sortBy<ISortedEmoji>(uniq(completions), sorters);

completions = completions.map(c => ({
return completions.map(c => ({
completion: c.emoji.unicode,
component: (
<PillCompletion title={`:${c.emoji.shortcodes[0]}:`} aria-label={c.emoji.unicode}>
Expand All @@ -153,7 +153,7 @@ export default class EmojiProvider extends AutocompleteProvider {
range,
}));
}
return completions;
return [];
}

getName() {
Expand Down
2 changes: 1 addition & 1 deletion src/components/structures/InteractiveAuth.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ export default class InteractiveAuthComponent extends React.Component<IProps, IS
});

if (this.props.poll) {
this.intervalId = setInterval(() => {
this.intervalId = window.setInterval(() => {
this.authLogic.poll();
}, 2000);
}
Expand Down
2 changes: 1 addition & 1 deletion src/components/structures/MatrixChat.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -1965,7 +1965,7 @@ export default class MatrixChat extends React.PureComponent<IProps, IState> {
this.accountPassword = password;
// self-destruct the password after 5mins
if (this.accountPasswordTimer !== null) clearTimeout(this.accountPasswordTimer);
this.accountPasswordTimer = setTimeout(() => {
this.accountPasswordTimer = window.setTimeout(() => {
this.accountPassword = null;
this.accountPasswordTimer = null;
}, 60 * 5 * 1000);
Expand Down
4 changes: 2 additions & 2 deletions src/components/structures/ScrollPanel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -459,7 +459,7 @@ export default class ScrollPanel extends React.Component<IProps> {
if (this.unfillDebouncer) {
clearTimeout(this.unfillDebouncer);
}
this.unfillDebouncer = setTimeout(() => {
this.unfillDebouncer = window.setTimeout(() => {
this.unfillDebouncer = null;
debuglog("unfilling now", { backwards, origExcessHeight });
this.props.onUnfillRequest?.(backwards, markerScrollToken!);
Expand All @@ -485,7 +485,7 @@ export default class ScrollPanel extends React.Component<IProps> {
// this will block the scroll event handler for +700ms
// if messages are already cached in memory,
// This would cause jumping to happen on Chrome/macOS.
return new Promise(resolve => setTimeout(resolve, 1)).then(() => {
return new Promise(resolve => window.setTimeout(resolve, 1)).then(() => {
return this.props.onFillRequest(backwards);
}).finally(() => {
this.pendingFillRequests[dir] = false;
Expand Down
2 changes: 1 addition & 1 deletion src/components/views/dialogs/InviteDialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -697,7 +697,7 @@ export default class InviteDialog extends React.PureComponent<Props, IInviteDial
if (this.debounceTimer) {
clearTimeout(this.debounceTimer);
}
this.debounceTimer = setTimeout(() => {
this.debounceTimer = window.setTimeout(() => {
this.updateSuggestions(term);
}, 150); // 150ms debounce (human reaction time + some)
};
Expand Down
2 changes: 1 addition & 1 deletion src/components/views/dialogs/SlidingSyncOptionsDialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ async function syncHealthCheck(cli: MatrixClient): Promise<void> {
*/
async function proxyHealthCheck(endpoint: string, hsUrl?: string): Promise<void> {
const controller = new AbortController();
const id = setTimeout(() => controller.abort(), 10 * 1000); // 10s
const id = window.setTimeout(() => controller.abort(), 10 * 1000); // 10s
const res = await fetch(endpoint + "/client/server.json", {
signal: controller.signal,
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ const VerificationRequestExplorer: React.FC<{
if (request.timeout == 0) return;

/* Note that request.timeout is a getter, so its value changes */
const id = setInterval(() => {
const id = window.setInterval(() => {
setRequestTimeout(request.timeout);
}, 500);

Expand Down
2 changes: 1 addition & 1 deletion src/components/views/dialogs/spotlight/SpotlightDialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ export const useWebSearchMetrics = (numResults: number, queryLength: number, via
if (!queryLength) return;

// send metrics after a 1s debounce
const timeoutId = setTimeout(() => {
const timeoutId = window.setTimeout(() => {
PosthogAnalytics.instance.trackEvent<WebSearchEvent>({
eventName: "WebSearch",
viaSpotlight,
Expand Down
4 changes: 2 additions & 2 deletions src/components/views/elements/DesktopCapturerSourcePicker.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -106,15 +106,15 @@ export default class DesktopCapturerSourcePicker extends React.Component<
}

async componentDidMount() {
// setInterval() first waits and then executes, therefore
// window.setInterval() first waits and then executes, therefore
// we call getDesktopCapturerSources() here without any delay.
// Otherwise the dialog would be left empty for some time.
this.setState({
sources: await getDesktopCapturerSources(),
});

// We update the sources every 500ms to get newer thumbnails
this.interval = setInterval(async () => {
this.interval = window.setInterval(async () => {
this.setState({
sources: await getDesktopCapturerSources(),
});
Expand Down
2 changes: 1 addition & 1 deletion src/components/views/elements/UseCaseSelection.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ export function UseCaseSelection({ onFinished }: Props) {
// Call onFinished 1.5s after `selection` becomes truthy, to give time for the animation to run
useEffect(() => {
if (selection) {
let handler: number | null = setTimeout(() => {
let handler: number | null = window.setTimeout(() => {
handler = null;
onFinished(selection);
}, TIMEOUT);
Expand Down
2 changes: 1 addition & 1 deletion src/components/views/emojipicker/EmojiPicker.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ class EmojiPicker extends React.Component<IProps, IState> {
this.setState({ filter });
// Header underlines need to be updated, but updating requires knowing
// where the categories are, so we wait for a tick.
setTimeout(this.updateVisibility, 0);
window.setTimeout(this.updateVisibility, 0);
};

private emojiMatchesFilter = (emoji: IEmoji, filter: string): boolean => {
Expand Down
4 changes: 2 additions & 2 deletions src/components/views/emojipicker/Search.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ class Search extends React.PureComponent<IProps> {
private inputRef = React.createRef<HTMLInputElement>();

componentDidMount() {
// For some reason, neither the autoFocus nor just calling focus() here worked, so here's a setTimeout
setTimeout(() => this.inputRef.current.focus(), 0);
// For some reason, neither the autoFocus nor just calling focus() here worked, so here's a window.setTimeout
window.setTimeout(() => this.inputRef.current.focus(), 0);
}

private onKeyDown = (ev: React.KeyboardEvent) => {
Expand Down
2 changes: 1 addition & 1 deletion src/components/views/messages/MImageBody.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -335,7 +335,7 @@ export default class MImageBody extends React.Component<IBodyProps, IState> {
// Add a 150ms timer for blurhash to first appear.
if (this.props.mxEvent.getContent().info?.[BLURHASH_FIELD]) {
this.clearBlurhashTimeout();
this.timeout = setTimeout(() => {
this.timeout = window.setTimeout(() => {
if (!this.state.imgLoaded || !this.state.imgError) {
this.setState({
placeholder: Placeholder.Blurhash,
Expand Down
2 changes: 1 addition & 1 deletion src/components/views/messages/TextualBody.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ export default class TextualBody extends React.Component<IBodyProps, IState> {
if (codes.length > 0) {
// Do this asynchronously: parsing code takes time and we don't
// need to block the DOM update on it.
setTimeout(() => {
window.setTimeout(() => {
if (this.unmounted) return;
for (let i = 0; i < codes.length; i++) {
this.highlightCode(codes[i]);
Expand Down
2 changes: 1 addition & 1 deletion src/components/views/rooms/Autocomplete.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ export default class Autocomplete extends React.PureComponent<IProps, IState> {
}

return new Promise((resolve) => {
this.debounceCompletionsRequest = setTimeout(() => {
this.debounceCompletionsRequest = window.setTimeout(() => {
resolve(this.processQuery(query, selection));
}, autocompleteDelay);
});
Expand Down
4 changes: 2 additions & 2 deletions src/components/views/rooms/MessageComposer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ export class MessageComposer extends React.Component<IProps, IState> {
// that the ScrollPanel listening to the resizeNotifier can
// correctly measure it's new height and scroll down to keep
// at the bottom if it already is
setTimeout(() => {
window.setTimeout(() => {
this.props.resizeNotifier.notifyTimelineHeightChanged();
}, 100);
}
Expand Down Expand Up @@ -395,7 +395,7 @@ export class MessageComposer extends React.Component<IProps, IState> {

private onRecordingEndingSoon = ({ secondsLeft }) => {
this.setState({ recordingTimeLeftSeconds: secondsLeft });
setTimeout(() => this.setState({ recordingTimeLeftSeconds: null }), 3000);
window.setTimeout(() => this.setState({ recordingTimeLeftSeconds: null }), 3000);
};

private setStickerPickerOpen = (isStickerPickerOpen: boolean) => {
Expand Down
2 changes: 1 addition & 1 deletion src/components/views/rooms/RoomBreadcrumbs.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ export default class RoomBreadcrumbs extends React.PureComponent<IProps, IState>
// again and this time we want to show the newest breadcrumb because it'll be hidden
// off screen for the animation.
this.setState({ doAnimation: false, skipFirst: true });
setTimeout(() => this.setState({ doAnimation: true, skipFirst: false }), 0);
window.setTimeout(() => this.setState({ doAnimation: true, skipFirst: false }), 0);
};

private viewRoom = (room: Room, index: number, viaKeyboard = false) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export function useIsFocused() {
} else {
// To avoid a blink when we switch mode between plain text and rich text mode
// We delay the unfocused action
timeoutIDRef.current = setTimeout(() => setIsFocused(false), 100);
timeoutIDRef.current = window.setTimeout(() => setIsFocused(false), 100);
}
}, [setIsFocused, timeoutIDRef]);

Expand Down
2 changes: 1 addition & 1 deletion src/components/views/rooms/wysiwyg_composer/hooks/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ export function focusComposer(
if (timeoutId.current) {
clearTimeout(timeoutId.current);
}
timeoutId.current = setTimeout(
timeoutId.current = window.setTimeout(
() => composerElement.current?.focus(),
200,
);
Expand Down
2 changes: 1 addition & 1 deletion src/components/views/settings/ThemeChoicePanel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ export default class ThemeChoicePanel extends React.Component<IProps, IState> {
await SettingsStore.setValue("custom_themes", null, SettingLevel.ACCOUNT, currentThemes);
this.setState({ customThemeUrl: "", customThemeMessage: { text: _t("Theme added!"), isError: false } });

this.themeTimer = setTimeout(() => {
this.themeTimer = window.setTimeout(() => {
this.setState({ customThemeMessage: { text: "", isError: false } });
}, 3000);
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ const SessionManagerTab: React.FC = () => {
const [expandedDeviceIds, setExpandedDeviceIds] = useState<ExtendedDevice['device_id'][]>([]);
const [selectedDeviceIds, setSelectedDeviceIds] = useState<ExtendedDevice['device_id'][]>([]);
const filteredDeviceListRef = useRef<HTMLDivElement>(null);
const scrollIntoViewTimeoutRef = useRef<ReturnType<typeof setTimeout>>();
const scrollIntoViewTimeoutRef = useRef<number>();

const matrixClient = useContext(MatrixClientContext);
const userId = matrixClient.getUserId();
Expand Down
2 changes: 1 addition & 1 deletion src/components/views/toasts/VerificationRequestToast.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ export default class VerificationRequestToast extends React.PureComponent<IProps
async componentDidMount() {
const { request } = this.props;
if (request.timeout && request.timeout > 0) {
this.intervalHandle = setInterval(() => {
this.intervalHandle = window.setInterval(() => {
let { counter } = this.state;
counter = Math.max(0, counter - 1);
this.setState({ counter });
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ export function UserOnboardingPage({ justRegistered = false }: Props) {
const [showList, setShowList] = useState<boolean>(false);
useEffect(() => {
if (initialSyncComplete) {
let handler: number | null = setTimeout(() => {
let handler: number | null = window.setTimeout(() => {
handler = null;
setShowList(true);
}, ANIMATION_DURATION);
Expand Down
2 changes: 1 addition & 1 deletion src/components/views/voip/CallDuration.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ interface GroupCallDurationProps {
export const GroupCallDuration: FC<GroupCallDurationProps> = ({ groupCall }) => {
const [now, setNow] = useState(() => Date.now());
useEffect(() => {
const timer = setInterval(() => setNow(Date.now()), 1000);
const timer = window.setInterval(() => setNow(Date.now()), 1000);
return () => clearInterval(timer);
}, []);

Expand Down
2 changes: 1 addition & 1 deletion src/dispatcher/dispatcher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ export class MatrixDispatcher extends Dispatcher<ActionPayload> {
// if you dispatch from within a dispatch, so rather than action
// handlers having to worry about not calling anything that might
// then dispatch, we just do dispatches asynchronously.
setTimeout(super.dispatch.bind(this, payload), 0);
window.setTimeout(super.dispatch.bind(this, payload), 0);
}
}

Expand Down
Loading

0 comments on commit d258402

Please sign in to comment.