From 84b1f2e6c6021fc6793c813466e395a854c3c555 Mon Sep 17 00:00:00 2001 From: "J. Ryan Stinnett" Date: Wed, 20 Jan 2021 13:40:46 +0000 Subject: [PATCH] Resolve typing errors after TypeScript upgrade --- src/BasePlatform.ts | 2 +- src/ContentMessages.tsx | 2 +- src/CountlyAnalytics.ts | 4 ++-- src/HtmlUtils.tsx | 2 ++ src/components/views/auth/PasswordLogin.tsx | 2 +- src/components/views/auth/RegistrationForm.tsx | 2 +- src/components/views/rooms/BasicMessageComposer.tsx | 2 +- src/rageshake/submit-rageshake.ts | 4 ++-- src/stores/AsyncStoreWithClient.ts | 4 ++-- src/stores/room-list/RoomListStore.ts | 4 ---- yarn.lock | 2 +- 11 files changed, 14 insertions(+), 16 deletions(-) diff --git a/src/BasePlatform.ts b/src/BasePlatform.ts index c301aa6a10..927de5a0a8 100644 --- a/src/BasePlatform.ts +++ b/src/BasePlatform.ts @@ -56,7 +56,7 @@ export default abstract class BasePlatform { this.startUpdateCheck = this.startUpdateCheck.bind(this); } - abstract async getConfig(): Promise<{}>; + abstract getConfig(): Promise<{}>; abstract getDefaultDeviceDisplayName(): string; diff --git a/src/ContentMessages.tsx b/src/ContentMessages.tsx index 5409a606de..bec36d49f6 100644 --- a/src/ContentMessages.tsx +++ b/src/ContentMessages.tsx @@ -497,7 +497,7 @@ export default class ContentMessages { content.info.mimetype = file.type; } - const prom = new Promise((resolve) => { + const prom = new Promise((resolve) => { if (file.type.indexOf('image/') === 0) { content.msgtype = 'm.image'; infoForImageFile(matrixClient, roomId, file).then((imageInfo) => { diff --git a/src/CountlyAnalytics.ts b/src/CountlyAnalytics.ts index b4727bc88b..974c08df18 100644 --- a/src/CountlyAnalytics.ts +++ b/src/CountlyAnalytics.ts @@ -840,7 +840,7 @@ export default class CountlyAnalytics { let endTime = CountlyAnalytics.getTimestamp(); const cli = MatrixClientPeg.get(); if (!cli.getRoom(roomId)) { - await new Promise(resolve => { + await new Promise(resolve => { const handler = (room) => { if (room.roomId === roomId) { cli.off("Room", handler); @@ -880,7 +880,7 @@ export default class CountlyAnalytics { let endTime = CountlyAnalytics.getTimestamp(); if (!room.findEventById(eventId)) { - await new Promise(resolve => { + await new Promise(resolve => { const handler = (ev) => { if (ev.getId() === eventId) { room.off("Room.localEchoUpdated", handler); diff --git a/src/HtmlUtils.tsx b/src/HtmlUtils.tsx index 637c0a2696..7d6b049914 100644 --- a/src/HtmlUtils.tsx +++ b/src/HtmlUtils.tsx @@ -422,6 +422,8 @@ export function bodyToHtml(content: IContent, highlights: string[], opts: IOpts if (SettingsStore.getValue("feature_latex_maths")) { const phtml = cheerio.load(safeBody, { _useHtmlParser2: true, decodeEntities: false }) + // @ts-ignore - The types for `replaceWith` wrongly expect + // Cheerio instance to be returned. phtml('div, span[data-mx-maths!=""]').replaceWith(function(i, e) { return katex.renderToString( AllHtmlEntities.decode(phtml(e).attr('data-mx-maths')), diff --git a/src/components/views/auth/PasswordLogin.tsx b/src/components/views/auth/PasswordLogin.tsx index 84e583c3a5..b2a3d62f55 100644 --- a/src/components/views/auth/PasswordLogin.tsx +++ b/src/components/views/auth/PasswordLogin.tsx @@ -196,7 +196,7 @@ export default class PasswordLogin extends React.PureComponent { // Validation and state updates are async, so we need to wait for them to complete // first. Queue a `setState` callback and wait for it to resolve. - await new Promise(resolve => this.setState({}, resolve)); + await new Promise(resolve => this.setState({}, resolve)); if (this.allFieldsValid()) { return true; diff --git a/src/components/views/auth/RegistrationForm.tsx b/src/components/views/auth/RegistrationForm.tsx index a0c7ab7b4f..e42ed88f99 100644 --- a/src/components/views/auth/RegistrationForm.tsx +++ b/src/components/views/auth/RegistrationForm.tsx @@ -194,7 +194,7 @@ export default class RegistrationForm extends React.PureComponent this.setState({}, resolve)); + await new Promise(resolve => this.setState({}, resolve)); if (this.allFieldsValid()) { return true; diff --git a/src/components/views/rooms/BasicMessageComposer.tsx b/src/components/views/rooms/BasicMessageComposer.tsx index 2ececdeaed..017ce77166 100644 --- a/src/components/views/rooms/BasicMessageComposer.tsx +++ b/src/components/views/rooms/BasicMessageComposer.tsx @@ -519,7 +519,7 @@ export default class BasicMessageEditor extends React.Component private async tabCompleteName(event: React.KeyboardEvent) { try { - await new Promise(resolve => this.setState({showVisualBell: false}, resolve)); + await new Promise(resolve => this.setState({showVisualBell: false}, resolve)); const {model} = this.props; const caret = this.getCaret(); const position = model.positionForOffset(caret.offset, caret.atNodeEnd); diff --git a/src/rageshake/submit-rageshake.ts b/src/rageshake/submit-rageshake.ts index d361f6b0dd..29856b1a86 100644 --- a/src/rageshake/submit-rageshake.ts +++ b/src/rageshake/submit-rageshake.ts @@ -235,7 +235,7 @@ export async function downloadBugReport(opts: IOpts = {}) { let i = 0; for (const [key, value] of body.entries()) { if (key === 'compressed-log') { - await new Promise((resolve => { + await new Promise((resolve => { const reader = new FileReader(); reader.addEventListener('loadend', ev => { tape.append(`log-${i++}.log`, new TextDecoder().decode(ev.target.result as ArrayBuffer)); @@ -269,7 +269,7 @@ function uint8ToString(buf: Buffer) { } function _submitReport(endpoint: string, body: FormData, progressCallback: (string) => void) { - return new Promise((resolve, reject) => { + return new Promise((resolve, reject) => { const req = new XMLHttpRequest(); req.open("POST", endpoint); req.timeout = 5 * 60 * 1000; diff --git a/src/stores/AsyncStoreWithClient.ts b/src/stores/AsyncStoreWithClient.ts index 38e709d8c2..7ed9bbd249 100644 --- a/src/stores/AsyncStoreWithClient.ts +++ b/src/stores/AsyncStoreWithClient.ts @@ -43,7 +43,7 @@ export abstract class AsyncStoreWithClient extends AsyncStore< })(dispatcher); } - protected get matrixClient(): MatrixClient { + get matrixClient(): MatrixClient { return this.readyStore.mxClient; } @@ -55,7 +55,7 @@ export abstract class AsyncStoreWithClient extends AsyncStore< // Default implementation is to do nothing. } - protected abstract async onAction(payload: ActionPayload); + protected abstract onAction(payload: ActionPayload): Promise; protected async onDispatch(payload: ActionPayload) { await this.onAction(payload); diff --git a/src/stores/room-list/RoomListStore.ts b/src/stores/room-list/RoomListStore.ts index 8c17da06fe..24a75c53e7 100644 --- a/src/stores/room-list/RoomListStore.ts +++ b/src/stores/room-list/RoomListStore.ts @@ -89,10 +89,6 @@ export class RoomListStoreClass extends AsyncStoreWithClient { return this.algorithm.getOrderedRooms(); } - public get matrixClient(): MatrixClient { - return super.matrixClient; - } - // Intended for test usage public async resetStore() { await this.reset(); diff --git a/yarn.lock b/yarn.lock index babe59c1bd..36affd13d6 100644 --- a/yarn.lock +++ b/yarn.lock @@ -6542,7 +6542,7 @@ qrcode@^1.4.4: pngjs "^3.3.0" yargs "^13.2.4" -qs@^6.9.4, qs@^6.9.6: +qs@^6.9.6: version "6.9.6" resolved "https://registry.yarnpkg.com/qs/-/qs-6.9.6.tgz#26ed3c8243a431b2924aca84cc90471f35d5a0ee" integrity sha512-TIRk4aqYLNoJUbd+g2lEdz5kLWIuTMRagAXxl78Q0RiVjAOugHmeKNGdd3cwo/ktpf9aL9epCfFqWDEKysUlLQ==