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

Commit d258402

Browse files
authored
Typescript updates (#9658)
* Typescript updates * Update @types/node * Fix more types
1 parent baaa9f5 commit d258402

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

59 files changed

+86
-90
lines changed

package.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@
160160
"@types/katex": "^0.14.0",
161161
"@types/lodash": "^4.14.168",
162162
"@types/modernizr": "^3.5.3",
163-
"@types/node": "^14.18.28",
163+
"@types/node": "^16",
164164
"@types/pako": "^1.0.1",
165165
"@types/parse5": "^6.0.0",
166166
"@types/qrcode": "^1.3.5",
@@ -212,7 +212,7 @@
212212
"stylelint": "^14.9.1",
213213
"stylelint-config-standard": "^26.0.0",
214214
"stylelint-scss": "^4.2.0",
215-
"typescript": "4.8.4",
215+
"typescript": "4.9.3",
216216
"walk": "^2.3.14"
217217
},
218218
"jest": {

src/@types/global.d.ts

-4
Original file line numberDiff line numberDiff line change
@@ -149,14 +149,10 @@ declare global {
149149

150150
// https://developer.mozilla.org/en-US/docs/Web/API/OffscreenCanvas
151151
interface OffscreenCanvas {
152-
height: number;
153-
width: number;
154-
getContext: HTMLCanvasElement["getContext"];
155152
convertToBlob(opts?: {
156153
type?: string;
157154
quality?: number;
158155
}): Promise<Blob>;
159-
transferToImageBitmap(): ImageBitmap;
160156
}
161157

162158
interface HTMLAudioElement {

src/DecryptionFailureTracker.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -174,12 +174,12 @@ export class DecryptionFailureTracker {
174174
* Start checking for and tracking failures.
175175
*/
176176
public start(): void {
177-
this.checkInterval = setInterval(
177+
this.checkInterval = window.setInterval(
178178
() => this.checkFailures(Date.now()),
179179
DecryptionFailureTracker.CHECK_INTERVAL_MS,
180180
);
181181

182-
this.trackInterval = setInterval(
182+
this.trackInterval = window.setInterval(
183183
() => this.trackFailures(),
184184
DecryptionFailureTracker.TRACK_INTERVAL_MS,
185185
);

src/LegacyCallHandler.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -254,7 +254,7 @@ export default class LegacyCallHandler extends EventEmitter {
254254
logger.log("Failed to check for protocol support and no retries remain: assuming no support", e);
255255
} else {
256256
logger.log("Failed to check for protocol support: will retry", e);
257-
setTimeout(() => {
257+
window.setTimeout(() => {
258258
this.checkProtocols(maxTries - 1);
259259
}, 10000);
260260
}

src/Lifecycle.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -584,7 +584,7 @@ async function doSetLoggedIn(
584584
// later than MatrixChat might assume.
585585
//
586586
// we fire it *synchronously* to make sure it fires before on_logged_in.
587-
// (dis.dispatch uses `setTimeout`, which does not guarantee ordering.)
587+
// (dis.dispatch uses `window.setTimeout`, which does not guarantee ordering.)
588588
dis.dispatch({ action: 'on_logging_in' }, true);
589589

590590
if (clearStorageEnabled) {
@@ -865,7 +865,7 @@ export async function onLoggedOut(): Promise<void> {
865865
if (SdkConfig.get().logout_redirect_url) {
866866
logger.log("Redirecting to external provider to finish logout");
867867
// XXX: Defer this so that it doesn't race with MatrixChat unmounting the world by going to /#/login
868-
setTimeout(() => {
868+
window.setTimeout(() => {
869869
window.location.href = SdkConfig.get().logout_redirect_url;
870870
}, 100);
871871
}

src/NodeAnimator.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ export default class NodeAnimator extends React.Component<IProps> {
119119
}
120120

121121
// and then we animate to the resting state
122-
setTimeout(() => {
122+
window.setTimeout(() => {
123123
this.applyStyles(domNode as HTMLElement, restingStyle);
124124
}, 0);
125125
}

src/PasswordReset.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ export default class PasswordReset {
119119
this.checkEmailLinkClicked()
120120
.then(() => resolve())
121121
.catch(() => {
122-
setTimeout(
122+
window.setTimeout(
123123
() => this.tryCheckEmailLinkClicked(resolve),
124124
CHECK_EMAIL_VERIFIED_POLL_INTERVAL,
125125
);

src/audio/PlaybackClock.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ export class PlaybackClock implements IDestroyable {
127127
// cast to number because the types are wrong
128128
// 100ms interval to make sure the time is as accurate as possible without
129129
// being overly insane
130-
this.timerId = <number><any>setInterval(this.checkTime, 100);
130+
this.timerId = <number><any>window.setInterval(this.checkTime, 100);
131131
}
132132
}
133133

src/autocomplete/Autocompleter.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ export interface ISelectionRange {
3535
}
3636

3737
export interface ICompletion {
38-
type: "at-room" | "command" | "community" | "room" | "user";
38+
type?: "at-room" | "command" | "community" | "room" | "user";
3939
completion: string;
4040
completionId?: string;
4141
component?: ReactElement;

src/autocomplete/EmojiProvider.tsx

+5-5
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ export default class EmojiProvider extends AutocompleteProvider {
103103
return []; // don't give any suggestions if the user doesn't want them
104104
}
105105

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

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

137137
completions = completions.slice(0, LIMIT);
138138

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

146-
completions = completions.map(c => ({
146+
return completions.map(c => ({
147147
completion: c.emoji.unicode,
148148
component: (
149149
<PillCompletion title={`:${c.emoji.shortcodes[0]}:`} aria-label={c.emoji.unicode}>
@@ -153,7 +153,7 @@ export default class EmojiProvider extends AutocompleteProvider {
153153
range,
154154
}));
155155
}
156-
return completions;
156+
return [];
157157
}
158158

159159
getName() {

src/components/structures/InteractiveAuth.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ export default class InteractiveAuthComponent extends React.Component<IProps, IS
127127
});
128128

129129
if (this.props.poll) {
130-
this.intervalId = setInterval(() => {
130+
this.intervalId = window.setInterval(() => {
131131
this.authLogic.poll();
132132
}, 2000);
133133
}

src/components/structures/MatrixChat.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -1965,7 +1965,7 @@ export default class MatrixChat extends React.PureComponent<IProps, IState> {
19651965
this.accountPassword = password;
19661966
// self-destruct the password after 5mins
19671967
if (this.accountPasswordTimer !== null) clearTimeout(this.accountPasswordTimer);
1968-
this.accountPasswordTimer = setTimeout(() => {
1968+
this.accountPasswordTimer = window.setTimeout(() => {
19691969
this.accountPassword = null;
19701970
this.accountPasswordTimer = null;
19711971
}, 60 * 5 * 1000);

src/components/structures/ScrollPanel.tsx

+2-2
Original file line numberDiff line numberDiff line change
@@ -459,7 +459,7 @@ export default class ScrollPanel extends React.Component<IProps> {
459459
if (this.unfillDebouncer) {
460460
clearTimeout(this.unfillDebouncer);
461461
}
462-
this.unfillDebouncer = setTimeout(() => {
462+
this.unfillDebouncer = window.setTimeout(() => {
463463
this.unfillDebouncer = null;
464464
debuglog("unfilling now", { backwards, origExcessHeight });
465465
this.props.onUnfillRequest?.(backwards, markerScrollToken!);
@@ -485,7 +485,7 @@ export default class ScrollPanel extends React.Component<IProps> {
485485
// this will block the scroll event handler for +700ms
486486
// if messages are already cached in memory,
487487
// This would cause jumping to happen on Chrome/macOS.
488-
return new Promise(resolve => setTimeout(resolve, 1)).then(() => {
488+
return new Promise(resolve => window.setTimeout(resolve, 1)).then(() => {
489489
return this.props.onFillRequest(backwards);
490490
}).finally(() => {
491491
this.pendingFillRequests[dir] = false;

src/components/views/dialogs/InviteDialog.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -697,7 +697,7 @@ export default class InviteDialog extends React.PureComponent<Props, IInviteDial
697697
if (this.debounceTimer) {
698698
clearTimeout(this.debounceTimer);
699699
}
700-
this.debounceTimer = setTimeout(() => {
700+
this.debounceTimer = window.setTimeout(() => {
701701
this.updateSuggestions(term);
702702
}, 150); // 150ms debounce (human reaction time + some)
703703
};

src/components/views/dialogs/SlidingSyncOptionsDialog.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ async function syncHealthCheck(cli: MatrixClient): Promise<void> {
4848
*/
4949
async function proxyHealthCheck(endpoint: string, hsUrl?: string): Promise<void> {
5050
const controller = new AbortController();
51-
const id = setTimeout(() => controller.abort(), 10 * 1000); // 10s
51+
const id = window.setTimeout(() => controller.abort(), 10 * 1000); // 10s
5252
const res = await fetch(endpoint + "/client/server.json", {
5353
signal: controller.signal,
5454
});

src/components/views/dialogs/devtools/VerificationExplorer.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ const VerificationRequestExplorer: React.FC<{
5151
if (request.timeout == 0) return;
5252

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

src/components/views/dialogs/spotlight/SpotlightDialog.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,7 @@ export const useWebSearchMetrics = (numResults: number, queryLength: number, via
228228
if (!queryLength) return;
229229

230230
// send metrics after a 1s debounce
231-
const timeoutId = setTimeout(() => {
231+
const timeoutId = window.setTimeout(() => {
232232
PosthogAnalytics.instance.trackEvent<WebSearchEvent>({
233233
eventName: "WebSearch",
234234
viaSpotlight,

src/components/views/elements/DesktopCapturerSourcePicker.tsx

+2-2
Original file line numberDiff line numberDiff line change
@@ -106,15 +106,15 @@ export default class DesktopCapturerSourcePicker extends React.Component<
106106
}
107107

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

116116
// We update the sources every 500ms to get newer thumbnails
117-
this.interval = setInterval(async () => {
117+
this.interval = window.setInterval(async () => {
118118
this.setState({
119119
sources: await getDesktopCapturerSources(),
120120
});

src/components/views/elements/UseCaseSelection.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ export function UseCaseSelection({ onFinished }: Props) {
3535
// Call onFinished 1.5s after `selection` becomes truthy, to give time for the animation to run
3636
useEffect(() => {
3737
if (selection) {
38-
let handler: number | null = setTimeout(() => {
38+
let handler: number | null = window.setTimeout(() => {
3939
handler = null;
4040
onFinished(selection);
4141
}, TIMEOUT);

src/components/views/emojipicker/EmojiPicker.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@ class EmojiPicker extends React.Component<IProps, IState> {
191191
this.setState({ filter });
192192
// Header underlines need to be updated, but updating requires knowing
193193
// where the categories are, so we wait for a tick.
194-
setTimeout(this.updateVisibility, 0);
194+
window.setTimeout(this.updateVisibility, 0);
195195
};
196196

197197
private emojiMatchesFilter = (emoji: IEmoji, filter: string): boolean => {

src/components/views/emojipicker/Search.tsx

+2-2
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,8 @@ class Search extends React.PureComponent<IProps> {
3131
private inputRef = React.createRef<HTMLInputElement>();
3232

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

3838
private onKeyDown = (ev: React.KeyboardEvent) => {

src/components/views/messages/MImageBody.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -335,7 +335,7 @@ export default class MImageBody extends React.Component<IBodyProps, IState> {
335335
// Add a 150ms timer for blurhash to first appear.
336336
if (this.props.mxEvent.getContent().info?.[BLURHASH_FIELD]) {
337337
this.clearBlurhashTimeout();
338-
this.timeout = setTimeout(() => {
338+
this.timeout = window.setTimeout(() => {
339339
if (!this.state.imgLoaded || !this.state.imgError) {
340340
this.setState({
341341
placeholder: Placeholder.Blurhash,

src/components/views/messages/TextualBody.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ export default class TextualBody extends React.Component<IBodyProps, IState> {
130130
if (codes.length > 0) {
131131
// Do this asynchronously: parsing code takes time and we don't
132132
// need to block the DOM update on it.
133-
setTimeout(() => {
133+
window.setTimeout(() => {
134134
if (this.unmounted) return;
135135
for (let i = 0; i < codes.length; i++) {
136136
this.highlightCode(codes[i]);

src/components/views/rooms/Autocomplete.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ export default class Autocomplete extends React.PureComponent<IProps, IState> {
127127
}
128128

129129
return new Promise((resolve) => {
130-
this.debounceCompletionsRequest = setTimeout(() => {
130+
this.debounceCompletionsRequest = window.setTimeout(() => {
131131
resolve(this.processQuery(query, selection));
132132
}, autocompleteDelay);
133133
});

src/components/views/rooms/MessageComposer.tsx

+2-2
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,7 @@ export class MessageComposer extends React.Component<IProps, IState> {
199199
// that the ScrollPanel listening to the resizeNotifier can
200200
// correctly measure it's new height and scroll down to keep
201201
// at the bottom if it already is
202-
setTimeout(() => {
202+
window.setTimeout(() => {
203203
this.props.resizeNotifier.notifyTimelineHeightChanged();
204204
}, 100);
205205
}
@@ -395,7 +395,7 @@ export class MessageComposer extends React.Component<IProps, IState> {
395395

396396
private onRecordingEndingSoon = ({ secondsLeft }) => {
397397
this.setState({ recordingTimeLeftSeconds: secondsLeft });
398-
setTimeout(() => this.setState({ recordingTimeLeftSeconds: null }), 3000);
398+
window.setTimeout(() => this.setState({ recordingTimeLeftSeconds: null }), 3000);
399399
};
400400

401401
private setStickerPickerOpen = (isStickerPickerOpen: boolean) => {

src/components/views/rooms/RoomBreadcrumbs.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ export default class RoomBreadcrumbs extends React.PureComponent<IProps, IState>
9999
// again and this time we want to show the newest breadcrumb because it'll be hidden
100100
// off screen for the animation.
101101
this.setState({ doAnimation: false, skipFirst: true });
102-
setTimeout(() => this.setState({ doAnimation: true, skipFirst: false }), 0);
102+
window.setTimeout(() => this.setState({ doAnimation: true, skipFirst: false }), 0);
103103
};
104104

105105
private viewRoom = (room: Room, index: number, viaKeyboard = false) => {

src/components/views/rooms/wysiwyg_composer/hooks/useIsFocused.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ export function useIsFocused() {
2828
} else {
2929
// To avoid a blink when we switch mode between plain text and rich text mode
3030
// We delay the unfocused action
31-
timeoutIDRef.current = setTimeout(() => setIsFocused(false), 100);
31+
timeoutIDRef.current = window.setTimeout(() => setIsFocused(false), 100);
3232
}
3333
}, [setIsFocused, timeoutIDRef]);
3434

src/components/views/rooms/wysiwyg_composer/hooks/utils.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ export function focusComposer(
3737
if (timeoutId.current) {
3838
clearTimeout(timeoutId.current);
3939
}
40-
timeoutId.current = setTimeout(
40+
timeoutId.current = window.setTimeout(
4141
() => composerElement.current?.focus(),
4242
200,
4343
);

src/components/views/settings/ThemeChoicePanel.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ export default class ThemeChoicePanel extends React.Component<IProps, IState> {
150150
await SettingsStore.setValue("custom_themes", null, SettingLevel.ACCOUNT, currentThemes);
151151
this.setState({ customThemeUrl: "", customThemeMessage: { text: _t("Theme added!"), isError: false } });
152152

153-
this.themeTimer = setTimeout(() => {
153+
this.themeTimer = window.setTimeout(() => {
154154
this.setState({ customThemeMessage: { text: "", isError: false } });
155155
}, 3000);
156156
};

src/components/views/settings/tabs/user/SessionManagerTab.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ const SessionManagerTab: React.FC = () => {
127127
const [expandedDeviceIds, setExpandedDeviceIds] = useState<ExtendedDevice['device_id'][]>([]);
128128
const [selectedDeviceIds, setSelectedDeviceIds] = useState<ExtendedDevice['device_id'][]>([]);
129129
const filteredDeviceListRef = useRef<HTMLDivElement>(null);
130-
const scrollIntoViewTimeoutRef = useRef<ReturnType<typeof setTimeout>>();
130+
const scrollIntoViewTimeoutRef = useRef<number>();
131131

132132
const matrixClient = useContext(MatrixClientContext);
133133
const userId = matrixClient.getUserId();

src/components/views/toasts/VerificationRequestToast.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ export default class VerificationRequestToast extends React.PureComponent<IProps
5757
async componentDidMount() {
5858
const { request } = this.props;
5959
if (request.timeout && request.timeout > 0) {
60-
this.intervalHandle = setInterval(() => {
60+
this.intervalHandle = window.setInterval(() => {
6161
let { counter } = this.state;
6262
counter = Math.max(0, counter - 1);
6363
this.setState({ counter });

src/components/views/user-onboarding/UserOnboardingPage.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ export function UserOnboardingPage({ justRegistered = false }: Props) {
5555
const [showList, setShowList] = useState<boolean>(false);
5656
useEffect(() => {
5757
if (initialSyncComplete) {
58-
let handler: number | null = setTimeout(() => {
58+
let handler: number | null = window.setTimeout(() => {
5959
handler = null;
6060
setShowList(true);
6161
}, ANIMATION_DURATION);

src/components/views/voip/CallDuration.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ interface GroupCallDurationProps {
4343
export const GroupCallDuration: FC<GroupCallDurationProps> = ({ groupCall }) => {
4444
const [now, setNow] = useState(() => Date.now());
4545
useEffect(() => {
46-
const timer = setInterval(() => setNow(Date.now()), 1000);
46+
const timer = window.setInterval(() => setNow(Date.now()), 1000);
4747
return () => clearInterval(timer);
4848
}, []);
4949

src/dispatcher/dispatcher.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ export class MatrixDispatcher extends Dispatcher<ActionPayload> {
4949
// if you dispatch from within a dispatch, so rather than action
5050
// handlers having to worry about not calling anything that might
5151
// then dispatch, we just do dispatches asynchronously.
52-
setTimeout(super.dispatch.bind(this, payload), 0);
52+
window.setTimeout(super.dispatch.bind(this, payload), 0);
5353
}
5454
}
5555

0 commit comments

Comments
 (0)