Skip to content

Commit 6836a5f

Browse files
authored
Conform more code to strictNullChecks and noImplicitAny (matrix-org#11156)
1 parent 46eb34a commit 6836a5f

File tree

9 files changed

+36
-19
lines changed

9 files changed

+36
-19
lines changed

src/Lifecycle.ts

+10-2
Original file line numberDiff line numberDiff line change
@@ -686,14 +686,22 @@ async function persistCredentials(credentials: IMatrixClientCreds): Promise<void
686686
// if we couldn't save to indexedDB, fall back to localStorage. We
687687
// store the access token unencrypted since localStorage only saves
688688
// strings.
689-
localStorage.setItem("mx_access_token", credentials.accessToken);
689+
if (!!credentials.accessToken) {
690+
localStorage.setItem("mx_access_token", credentials.accessToken);
691+
} else {
692+
localStorage.removeItem("mx_access_token");
693+
}
690694
}
691695
localStorage.setItem("mx_has_pickle_key", String(true));
692696
} else {
693697
try {
694698
await StorageManager.idbSave("account", "mx_access_token", credentials.accessToken);
695699
} catch (e) {
696-
localStorage.setItem("mx_access_token", credentials.accessToken);
700+
if (!!credentials.accessToken) {
701+
localStorage.setItem("mx_access_token", credentials.accessToken);
702+
} else {
703+
localStorage.removeItem("mx_access_token");
704+
}
697705
}
698706
if (localStorage.getItem("mx_has_pickle_key") === "true") {
699707
logger.error("Expected a pickle key, but none provided. Encryption may not work.");

src/components/structures/RoomView.tsx

+14-8
Original file line numberDiff line numberDiff line change
@@ -1597,14 +1597,15 @@ export class RoomView extends React.Component<IRoomProps, IRoomState> {
15971597
};
15981598

15991599
private injectSticker(url: string, info: object, text: string, threadId: string | null): void {
1600-
if (!this.context.client) return;
1600+
const roomId = this.getRoomId();
1601+
if (!this.context.client || !roomId) return;
16011602
if (this.context.client.isGuest()) {
16021603
dis.dispatch({ action: "require_registration" });
16031604
return;
16041605
}
16051606

16061607
ContentMessages.sharedInstance()
1607-
.sendStickerContentToRoom(url, this.getRoomId(), threadId, info, text, this.context.client)
1608+
.sendStickerContentToRoom(url, roomId, threadId, info, text, this.context.client)
16081609
.then(undefined, (error) => {
16091610
if (error.name === "UnknownDeviceError") {
16101611
// Let the staus bar handle this
@@ -1636,7 +1637,7 @@ export class RoomView extends React.Component<IRoomProps, IRoomState> {
16361637
private onSearchUpdate = (inProgress: boolean, searchResults: ISearchResults | null): void => {
16371638
this.setState({
16381639
search: {
1639-
...this.state.search,
1640+
...this.state.search!,
16401641
count: searchResults?.count,
16411642
inProgress,
16421643
},
@@ -1658,10 +1659,12 @@ export class RoomView extends React.Component<IRoomProps, IRoomState> {
16581659
};
16591660

16601661
private onRejectButtonClicked = (): void => {
1662+
const roomId = this.getRoomId();
1663+
if (!roomId) return;
16611664
this.setState({
16621665
rejecting: true,
16631666
});
1664-
this.context.client?.leave(this.getRoomId()).then(
1667+
this.context.client?.leave(roomId).then(
16651668
() => {
16661669
dis.dispatch({ action: Action.ViewHomePage });
16671670
this.setState({
@@ -1896,14 +1899,17 @@ export class RoomView extends React.Component<IRoomProps, IRoomState> {
18961899
});
18971900
}
18981901

1899-
private onFileDrop = (dataTransfer: DataTransfer): Promise<void> =>
1900-
ContentMessages.sharedInstance().sendContentListToRoom(
1902+
private onFileDrop = async (dataTransfer: DataTransfer): Promise<void> => {
1903+
const roomId = this.getRoomId();
1904+
if (!roomId || !this.context.client) return;
1905+
await ContentMessages.sharedInstance().sendContentListToRoom(
19011906
Array.from(dataTransfer.files),
1902-
this.getRoomId(),
1903-
null,
1907+
roomId,
1908+
undefined,
19041909
this.context.client,
19051910
TimelineRenderingType.Room,
19061911
);
1912+
};
19071913

19081914
private onMeasurement = (narrow: boolean): void => {
19091915
this.setState({ narrow });

src/components/structures/ScrollPanel.tsx

+1
Original file line numberDiff line numberDiff line change
@@ -830,6 +830,7 @@ export default class ScrollPanel extends React.Component<IProps> {
830830
}
831831

832832
private topFromBottom(node: HTMLElement): number {
833+
if (!this.itemlist.current) return -1;
833834
// current capped height - distance from top = distance from bottom of container to top of tracked element
834835
return this.itemlist.current.clientHeight - node.offsetTop;
835836
}

test/components/structures/SpaceHierarchy-test.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ describe("SpaceHierarchy", () => {
166166
observe: () => null,
167167
unobserve: () => null,
168168
disconnect: () => null,
169-
});
169+
} as ResizeObserver);
170170
window.IntersectionObserver = mockIntersectionObserver;
171171
});
172172

test/components/structures/TimelinePanel-test.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ const mkTimeline = (room: Room, events: MatrixEvent[]): [EventTimeline, EventTim
7070
room: room as Room,
7171
getLiveTimeline: () => timeline,
7272
getTimelineForEvent: () => timeline,
73-
getPendingEvents: () => [],
73+
getPendingEvents: () => [] as MatrixEvent[],
7474
} as unknown as EventTimelineSet;
7575
const timeline = new EventTimeline(timelineSet);
7676
events.forEach((event) => timeline.addEvent(event, { toStartOfTimeline: false }));

test/components/views/right_panel/VerificationPanel-test.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,7 @@ function renderComponent(props: Partial<ComponentProps<typeof VerificationPanel>
185185
const defaultProps = {
186186
layout: "",
187187
member: {} as User,
188-
onClose: () => undefined,
188+
onClose: () => {},
189189
isRoomEncrypted: false,
190190
inDialog: false,
191191
phase: props.request.phase,

test/components/views/spaces/SpacePanel-test.tsx

+4-3
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ limitations under the License.
1717
import React from "react";
1818
import { render, screen, fireEvent, act } from "@testing-library/react";
1919
import { mocked } from "jest-mock";
20-
import { MatrixClient } from "matrix-js-sdk/src/matrix";
20+
import { MatrixClient, Room } from "matrix-js-sdk/src/matrix";
2121

2222
import UnwrappedSpacePanel from "../../../../src/components/views/spaces/SpacePanel";
2323
import { MatrixClientPeg } from "../../../../src/MatrixClientPeg";
@@ -28,6 +28,7 @@ import { mkStubRoom, wrapInSdkContext } from "../../../test-utils";
2828
import { SdkContextClass } from "../../../../src/contexts/SDKContext";
2929
import SpaceStore from "../../../../src/stores/spaces/SpaceStore";
3030
import DMRoomMap from "../../../../src/utils/DMRoomMap";
31+
import { SpaceNotificationState } from "../../../../src/stores/notifications/SpaceNotificationState";
3132

3233
// DND test utilities based on
3334
// https://github.com/colinrobertbrooks/react-beautiful-dnd-test-utils/issues/18#issuecomment-1373388693
@@ -98,8 +99,8 @@ jest.mock("../../../../src/stores/spaces/SpaceStore", () => {
9899
enabledMetaSpaces: MetaSpace[] = [];
99100
spacePanelSpaces: string[] = [];
100101
activeSpace: SpaceKey = "!space1";
101-
getChildSpaces = () => [];
102-
getNotificationState = () => null;
102+
getChildSpaces = () => [] as Room[];
103+
getNotificationState = () => null as SpaceNotificationState | null;
103104
setActiveSpace = jest.fn();
104105
moveRootSpace = jest.fn();
105106
}

test/utils/AutoDiscoveryUtils-test.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,7 @@ describe("AutoDiscoveryUtils", () => {
214214
registrationEndpoint: "https://test.com/registration",
215215
tokenEndpoint: "https://test.com/token",
216216
};
217-
const discoveryResult = {
217+
const discoveryResult: ClientConfig = {
218218
...validIsConfig,
219219
...validHsConfig,
220220
[M_AUTHENTICATION.stable!]: {

test/utils/oidc/registerClient-test.ts

+3-2
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import fetchMockJest from "fetch-mock-jest";
1818
import { OidcError } from "matrix-js-sdk/src/oidc/error";
1919

2020
import { getOidcClientId } from "../../../src/utils/oidc/registerClient";
21+
import { ValidatedDelegatedAuthConfig } from "../../../src/utils/ValidatedServerConfig";
2122

2223
describe("getOidcClientId()", () => {
2324
const issuer = "https://auth.com/";
@@ -49,7 +50,7 @@ describe("getOidcClientId()", () => {
4950
});
5051

5152
it("should throw when no static clientId is configured and no registration endpoint", async () => {
52-
const authConfigWithoutRegistration = {
53+
const authConfigWithoutRegistration: ValidatedDelegatedAuthConfig = {
5354
...delegatedAuthConfig,
5455
issuer: "https://issuerWithoutStaticClientId.org/",
5556
registrationEndpoint: undefined,
@@ -62,7 +63,7 @@ describe("getOidcClientId()", () => {
6263
});
6364

6465
it("should handle when staticOidcClients object is falsy", async () => {
65-
const authConfigWithoutRegistration = {
66+
const authConfigWithoutRegistration: ValidatedDelegatedAuthConfig = {
6667
...delegatedAuthConfig,
6768
registrationEndpoint: undefined,
6869
};

0 commit comments

Comments
 (0)