From b77b2df29bb100fd57560b6d459e6114e326e70e Mon Sep 17 00:00:00 2001 From: Michael Telatynski <7t3chguy@gmail.com> Date: Tue, 4 Apr 2023 14:01:04 +0100 Subject: [PATCH] Improve context types (#10510) --- src/contexts/MatrixClientContext.tsx | 5 ++++- src/contexts/SDKContext.ts | 5 ++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/src/contexts/MatrixClientContext.tsx b/src/contexts/MatrixClientContext.tsx index 4c02f066b6..da351b1574 100644 --- a/src/contexts/MatrixClientContext.tsx +++ b/src/contexts/MatrixClientContext.tsx @@ -25,7 +25,10 @@ import React, { } from "react"; import { MatrixClient } from "matrix-js-sdk/src/client"; -const MatrixClientContext = createContext(undefined); +// This context is available to components under LoggedInView, +// the context must not be used by components outside a MatrixClientContext tree. +// This assertion allows us to make the type not nullable. +const MatrixClientContext = createContext(null as any); MatrixClientContext.displayName = "MatrixClientContext"; export default MatrixClientContext; diff --git a/src/contexts/SDKContext.ts b/src/contexts/SDKContext.ts index 82b47d09c4..bb10d0df72 100644 --- a/src/contexts/SDKContext.ts +++ b/src/contexts/SDKContext.ts @@ -38,7 +38,10 @@ import { VoiceBroadcastRecordingsStore, } from "../voice-broadcast"; -export const SDKContext = createContext(undefined); +// This context is available to components under MatrixChat, +// the context must not be used by components outside a SdkContextClass tree. +// This assertion allows us to make the type not nullable. +export const SDKContext = createContext(null as any); SDKContext.displayName = "SDKContext"; /**