From 9e6467c684ea35dc542821833e178b70fa6e2ea4 Mon Sep 17 00:00:00 2001 From: Michael Telatynski <7t3chguy@gmail.com> Date: Fri, 5 May 2023 09:08:36 +0100 Subject: [PATCH] Improve quality of Typescripting (#25232) --- .../structures/CompatibilityView.tsx | 2 +- src/components/views/auth/VectorAuthFooter.tsx | 2 +- src/favicon.ts | 2 +- src/vector/index.ts | 7 ++++--- src/vector/platform/VectorBasePlatform.ts | 2 +- tsconfig.json | 12 +++++++++++- 6 files changed, 19 insertions(+), 8 deletions(-) diff --git a/src/async-components/structures/CompatibilityView.tsx b/src/async-components/structures/CompatibilityView.tsx index dde0aea256..c6aafe0f82 100644 --- a/src/async-components/structures/CompatibilityView.tsx +++ b/src/async-components/structures/CompatibilityView.tsx @@ -30,7 +30,7 @@ const CompatibilityView: React.FC = ({ onAccept }) => { const brand = SdkConfig.get("brand"); const mobileBuilds = SdkConfig.get("mobile_builds"); - let ios = null; + let ios: JSX.Element | undefined; const iosCustomUrl = mobileBuilds?.ios; if (iosCustomUrl !== null) { // could be undefined or a string diff --git a/src/components/views/auth/VectorAuthFooter.tsx b/src/components/views/auth/VectorAuthFooter.tsx index 26ad2c64ac..0ef54ea80d 100644 --- a/src/components/views/auth/VectorAuthFooter.tsx +++ b/src/components/views/auth/VectorAuthFooter.tsx @@ -27,7 +27,7 @@ const VectorAuthFooter = (): ReactElement => { { text: "GitHub", url: "https://github.com/vector-im/element-web" }, ]; - const authFooterLinks = []; + const authFooterLinks: JSX.Element[] = []; for (const linkEntry of links) { authFooterLinks.push( diff --git a/src/favicon.ts b/src/favicon.ts index 9f4fbec392..5b8109501f 100644 --- a/src/favicon.ts +++ b/src/favicon.ts @@ -49,7 +49,7 @@ export default class Favicon { private readonly params: IParams; private readonly canvas: HTMLCanvasElement; private readonly baseImage: HTMLImageElement; - private context: CanvasRenderingContext2D; + private context!: CanvasRenderingContext2D; private icons: HTMLLinkElement[]; private isReady = false; diff --git a/src/vector/index.ts b/src/vector/index.ts index 56d87e4fd0..d0a3a6e3ae 100644 --- a/src/vector/index.ts +++ b/src/vector/index.ts @@ -19,6 +19,7 @@ limitations under the License. */ import { logger } from "matrix-js-sdk/src/logger"; +import { extractErrorMessageFromError } from "matrix-react-sdk/src/components/views/dialogs/ErrorDialog"; // These are things that can run before the skin loads - be careful not to reference the react-sdk though. import { parseQsFromFragment } from "./url_utils"; @@ -194,7 +195,7 @@ async function start(): Promise { await loadConfigPromise; } catch (error) { // Now that we've loaded the theme (CSS), display the config syntax error if needed. - if (error.err && error.err instanceof SyntaxError) { + if (error instanceof SyntaxError) { // This uses the default brand since the app config is unavailable. return showError(_t("Your Element is misconfigured"), [ _t( @@ -202,7 +203,7 @@ async function start(): Promise { "Please correct the problem and reload the page.", ), _t("The message from the parser is: %(message)s", { - message: error.err.message || _t("Invalid JSON"), + message: error.message || _t("Invalid JSON"), }), ]); } @@ -231,7 +232,7 @@ async function start(): Promise { // Like the compatibility page, AWOOOOOGA at the user // This uses the default brand since the app config is unavailable. await showError(_t("Your Element is misconfigured"), [ - err.translatedMessage || _t("Unexpected error preparing the app. See console for details."), + extractErrorMessageFromError(err, _t("Unexpected error preparing the app. See console for details.")), ]); } } diff --git a/src/vector/platform/VectorBasePlatform.ts b/src/vector/platform/VectorBasePlatform.ts index fccb6119c9..4f67b1e332 100644 --- a/src/vector/platform/VectorBasePlatform.ts +++ b/src/vector/platform/VectorBasePlatform.ts @@ -28,7 +28,7 @@ import Favicon from "../../favicon"; * Vector-specific extensions to the BasePlatform template */ export default abstract class VectorBasePlatform extends BasePlatform { - protected _favicon: Favicon; + protected _favicon?: Favicon; public async getConfig(): Promise { return getVectorConfig(); diff --git a/tsconfig.json b/tsconfig.json index 50b20450ea..f2ee3b70cf 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -18,5 +18,15 @@ "strictBindCallApply": true, "noImplicitThis": true }, - "include": ["./src/**/*.ts", "./src/**/*.tsx", "./test/**/*.ts", "./test/**/*.tsx"] + "include": [ + "./node_modules/matrix-js-sdk/src/@types/*.d.ts", + "./node_modules/matrix-react-sdk/src/@types/diff-dom.d.ts", + "./node_modules/matrix-react-sdk/src/@types/opus-recorder.d.ts", + "./node_modules/matrix-react-sdk/src/@types/png-chunks-extract.d.ts", + "./node_modules/matrix-react-sdk/src/@types/sanitize-html.d.ts", + "./src/**/*.ts", + "./src/**/*.tsx", + "./test/**/*.ts", + "./test/**/*.tsx" + ] }