Improve typescript null checking in places (#10073 (#10073

* Improve typescript null checking in places

* Iterate

* Fix Timer.ts
This commit is contained in:
Michael Telatynski
2023-02-03 15:27:47 +00:00
committed by GitHub
parent 97506cbcdb
commit 9743852380
43 changed files with 155 additions and 154 deletions

View File

@@ -50,8 +50,8 @@ export class OwnProfileStore extends AsyncStoreWithClient<IState> {
// round-trip after the client is ready, and we often load widgets in that time, and we'd
// and up passing them an incorrect display name
super(defaultDispatcher, {
displayName: window.localStorage.getItem(KEY_DISPLAY_NAME),
avatarUrl: window.localStorage.getItem(KEY_AVATAR_URL),
displayName: window.localStorage.getItem(KEY_DISPLAY_NAME) || undefined,
avatarUrl: window.localStorage.getItem(KEY_AVATAR_URL) || undefined,
});
}

View File

@@ -25,7 +25,7 @@ import { IDestroyable } from "../utils/IDestroyable";
import { Action } from "../dispatcher/actions";
export abstract class ReadyWatchingStore extends EventEmitter implements IDestroyable {
protected matrixClient: MatrixClient;
protected matrixClient: MatrixClient | null = null;
private dispatcherRef: string | null = null;
public constructor(protected readonly dispatcher: Dispatcher<ActionPayload>) {
@@ -42,7 +42,7 @@ export abstract class ReadyWatchingStore extends EventEmitter implements IDestro
}
}
public get mxClient(): MatrixClient {
public get mxClient(): MatrixClient | null {
return this.matrixClient; // for external readonly access
}

View File

@@ -21,7 +21,7 @@ export enum UI_EVENTS {
}
export default class UIStore extends EventEmitter {
private static _instance: UIStore = null;
private static _instance: UIStore | null = null;
private resizeObserver: ResizeObserver;
@@ -58,7 +58,7 @@ export default class UIStore extends EventEmitter {
}
}
public getElementDimensions(name: string): DOMRectReadOnly {
public getElementDimensions(name: string): DOMRectReadOnly | undefined {
return this.uiElementDimensions.get(name);
}
@@ -68,7 +68,7 @@ export default class UIStore extends EventEmitter {
}
public stopTrackingElementDimensions(name: string): void {
let trackedElement: Element;
let trackedElement: Element | undefined;
this.trackedUiElements.forEach((trackedElementName, element) => {
if (trackedElementName === name) {
trackedElement = element;

View File

@@ -66,7 +66,7 @@ export const flattenSpaceHierarchyWithCache =
useCache = true,
): Set<string> => {
if (useCache && cache.has(spaceId)) {
return cache.get(spaceId);
return cache.get(spaceId)!;
}
const result = flattenSpaceHierarchy(spaceEntityMap, spaceDescendantMap, spaceId);
cache.set(spaceId, result);