Conform more of the codebase to strict types (#11162)

This commit is contained in:
Michael Telatynski 2023-06-29 12:17:05 +01:00 committed by GitHub
parent 9c7d935aae
commit 95283d21bb
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
9 changed files with 36 additions and 31 deletions

View file

@ -58,7 +58,7 @@ export type Binding = {
* https://gist.github.com/jryans/839a09bf0c5a70e2f36ed990d50ed928 * https://gist.github.com/jryans/839a09bf0c5a70e2f36ed990d50ed928
*/ */
export default class AddThreepid { export default class AddThreepid {
private sessionId: string; private sessionId?: string;
private submitUrl?: string; private submitUrl?: string;
private bind = false; private bind = false;
private readonly clientSecret: string; private readonly clientSecret: string;
@ -202,7 +202,7 @@ export default class AddThreepid {
throw new UserFriendlyError("No identity access token found"); throw new UserFriendlyError("No identity access token found");
} }
await this.matrixClient.bindThreePid({ await this.matrixClient.bindThreePid({
sid: this.sessionId, sid: this.sessionId!,
client_secret: this.clientSecret, client_secret: this.clientSecret,
id_server: getIdServerDomain(this.matrixClient), id_server: getIdServerDomain(this.matrixClient),
id_access_token: identityAccessToken, id_access_token: identityAccessToken,
@ -278,7 +278,7 @@ export default class AddThreepid {
*/ */
private makeAddThreepidOnlyRequest = (auth?: IAddThreePidOnlyBody["auth"] | null): Promise<{}> => { private makeAddThreepidOnlyRequest = (auth?: IAddThreePidOnlyBody["auth"] | null): Promise<{}> => {
return this.matrixClient.addThreePidOnly({ return this.matrixClient.addThreePidOnly({
sid: this.sessionId, sid: this.sessionId!,
client_secret: this.clientSecret, client_secret: this.clientSecret,
auth: auth ?? undefined, auth: auth ?? undefined,
}); });
@ -302,13 +302,13 @@ export default class AddThreepid {
if (this.submitUrl) { if (this.submitUrl) {
result = await this.matrixClient.submitMsisdnTokenOtherUrl( result = await this.matrixClient.submitMsisdnTokenOtherUrl(
this.submitUrl, this.submitUrl,
this.sessionId, this.sessionId!,
this.clientSecret, this.clientSecret,
msisdnToken, msisdnToken,
); );
} else if (this.bind || !supportsSeparateAddAndBind) { } else if (this.bind || !supportsSeparateAddAndBind) {
result = await this.matrixClient.submitMsisdnToken( result = await this.matrixClient.submitMsisdnToken(
this.sessionId, this.sessionId!,
this.clientSecret, this.clientSecret,
msisdnToken, msisdnToken,
await authClient.getAccessToken(), await authClient.getAccessToken(),
@ -323,7 +323,7 @@ export default class AddThreepid {
if (supportsSeparateAddAndBind) { if (supportsSeparateAddAndBind) {
if (this.bind) { if (this.bind) {
await this.matrixClient.bindThreePid({ await this.matrixClient.bindThreePid({
sid: this.sessionId, sid: this.sessionId!,
client_secret: this.clientSecret, client_secret: this.clientSecret,
id_server: getIdServerDomain(this.matrixClient), id_server: getIdServerDomain(this.matrixClient),
id_access_token: await authClient.getAccessToken(), id_access_token: await authClient.getAccessToken(),

View file

@ -29,9 +29,11 @@ const DIALOG_CONTAINER_ID = "mx_Dialog_Container";
const STATIC_DIALOG_CONTAINER_ID = "mx_Dialog_StaticContainer"; const STATIC_DIALOG_CONTAINER_ID = "mx_Dialog_StaticContainer";
// Type which accepts a React Component which looks like a Modal (accepts an onFinished prop) // Type which accepts a React Component which looks like a Modal (accepts an onFinished prop)
export type ComponentType = React.ComponentType<{ export type ComponentType =
onFinished(...args: any): void; | React.ComponentType<{
}>; onFinished(...args: any): void;
}>
| React.ComponentType<any>;
// Generic type which returns the props of the Modal component with the onFinished being optional. // Generic type which returns the props of the Modal component with the onFinished being optional.
export type ComponentProps<C extends ComponentType> = Defaultize< export type ComponentProps<C extends ComponentType> = Defaultize<

View file

@ -14,7 +14,7 @@ See the License for the specific language governing permissions and
limitations under the License. limitations under the License.
*/ */
import React, { Key, ReactElement, ReactInstance } from "react"; import React, { Key, ReactElement, ReactFragment, ReactInstance, ReactPortal } from "react";
import ReactDom from "react-dom"; import ReactDom from "react-dom";
interface IChildProps { interface IChildProps {
@ -33,6 +33,10 @@ interface IProps {
startStyles: React.CSSProperties[]; startStyles: React.CSSProperties[];
} }
function isReactElement(c: ReactElement | ReactFragment | ReactPortal): c is ReactElement {
return typeof c === "object" && "type" in c;
}
/** /**
* The NodeAnimator contains components and animates transitions. * The NodeAnimator contains components and animates transitions.
* It will only pick up direct changes to properties ('left', currently), and so * It will only pick up direct changes to properties ('left', currently), and so
@ -72,7 +76,8 @@ export default class NodeAnimator extends React.Component<IProps> {
private updateChildren(newChildren: React.ReactNode): void { private updateChildren(newChildren: React.ReactNode): void {
const oldChildren = this.children || {}; const oldChildren = this.children || {};
this.children = {}; this.children = {};
React.Children.toArray(newChildren).forEach((c: ReactElement) => { React.Children.toArray(newChildren).forEach((c) => {
if (!isReactElement(c)) return;
if (oldChildren[c.key!]) { if (oldChildren[c.key!]) {
const old = oldChildren[c.key!]; const old = oldChildren[c.key!];
const oldNode = ReactDom.findDOMNode(this.nodes[old.key!]); const oldNode = ReactDom.findDOMNode(this.nodes[old.key!]);

View file

@ -14,13 +14,12 @@ See the License for the specific language governing permissions and
limitations under the License. limitations under the License.
*/ */
import { ICryptoCallbacks } from "matrix-js-sdk/src/matrix"; import { DeviceVerificationStatus, ICryptoCallbacks } from "matrix-js-sdk/src/matrix";
import { ISecretStorageKeyInfo } from "matrix-js-sdk/src/crypto/api"; import { ISecretStorageKeyInfo } from "matrix-js-sdk/src/crypto/api";
import { MatrixClient } from "matrix-js-sdk/src/client"; import { MatrixClient } from "matrix-js-sdk/src/client";
import { deriveKey } from "matrix-js-sdk/src/crypto/key_passphrase"; import { deriveKey } from "matrix-js-sdk/src/crypto/key_passphrase";
import { decodeRecoveryKey } from "matrix-js-sdk/src/crypto/recoverykey"; import { decodeRecoveryKey } from "matrix-js-sdk/src/crypto/recoverykey";
import { encodeBase64 } from "matrix-js-sdk/src/crypto/olmlib"; import { encodeBase64 } from "matrix-js-sdk/src/crypto/olmlib";
import { DeviceTrustLevel } from "matrix-js-sdk/src/crypto/CrossSigning";
import { logger } from "matrix-js-sdk/src/logger"; import { logger } from "matrix-js-sdk/src/logger";
import type CreateSecretStorageDialog from "./async-components/views/dialogs/security/CreateSecretStorageDialog"; import type CreateSecretStorageDialog from "./async-components/views/dialogs/security/CreateSecretStorageDialog";
@ -241,7 +240,7 @@ async function onSecretRequested(
deviceId: string, deviceId: string,
requestId: string, requestId: string,
name: string, name: string,
deviceTrust: DeviceTrustLevel, deviceTrust: DeviceVerificationStatus,
): Promise<string | undefined> { ): Promise<string | undefined> {
logger.log("onSecretRequested", userId, deviceId, requestId, name, deviceTrust); logger.log("onSecretRequested", userId, deviceId, requestId, name, deviceTrust);
const client = MatrixClientPeg.safeGet(); const client = MatrixClientPeg.safeGet();

View file

@ -81,8 +81,8 @@ const singleMxcUpload = async (cli: MatrixClient): Promise<string | null> => {
return new Promise((resolve) => { return new Promise((resolve) => {
const fileSelector = document.createElement("input"); const fileSelector = document.createElement("input");
fileSelector.setAttribute("type", "file"); fileSelector.setAttribute("type", "file");
fileSelector.onchange = (ev: HTMLInputEvent) => { fileSelector.onchange = (ev: Event) => {
const file = ev.target.files?.[0]; const file = (ev as HTMLInputEvent).target.files?.[0];
if (!file) return; if (!file) return;
Modal.createDialog(UploadConfirmDialog, { Modal.createDialog(UploadConfirmDialog, {

View file

@ -47,9 +47,9 @@ interface ISortedEmoji {
const SORTED_EMOJI: ISortedEmoji[] = EMOJI.sort((a, b) => { const SORTED_EMOJI: ISortedEmoji[] = EMOJI.sort((a, b) => {
if (a.group === b.group) { if (a.group === b.group) {
return a.order - b.order; return a.order! - b.order!;
} }
return a.group - b.group; return a.group! - b.group!;
}).map((emoji, index) => ({ }).map((emoji, index) => ({
emoji, emoji,
// Include the index so that we can preserve the original order // Include the index so that we can preserve the original order

View file

@ -16,17 +16,11 @@ limitations under the License.
import EMOJIBASE from "emojibase-data/en/compact.json"; import EMOJIBASE from "emojibase-data/en/compact.json";
import SHORTCODES from "emojibase-data/en/shortcodes/iamcal.json"; import SHORTCODES from "emojibase-data/en/shortcodes/iamcal.json";
import { CompactEmoji } from "emojibase";
export interface IEmoji { export interface IEmoji extends Omit<CompactEmoji, "shortcodes"> {
label: string; // We generate a shortcode based on the label if none exist in the dataset
group: number;
hexcode: string;
order: number;
shortcodes: string[]; shortcodes: string[];
tags?: string[];
unicode: string;
skins?: Omit<IEmoji, "shortcodes" | "tags">[]; // Currently unused
emoticon?: string | string[];
} }
// The unicode is stored without the variant selector // The unicode is stored without the variant selector
@ -74,7 +68,7 @@ export const DATA_BY_CATEGORY: Record<string, IEmoji[]> = {
}; };
// Store various mappings from unicode/emoticon/shortcode to the Emoji objects // Store various mappings from unicode/emoticon/shortcode to the Emoji objects
export const EMOJI: IEmoji[] = EMOJIBASE.map((emojiData: Omit<IEmoji, "shortcodes">) => { export const EMOJI: IEmoji[] = EMOJIBASE.map((emojiData) => {
// If there's ever a gap in shortcode coverage, we fudge it by // If there's ever a gap in shortcode coverage, we fudge it by
// filling it in with the emoji's CLDR annotation // filling it in with the emoji's CLDR annotation
const shortcodeData = SHORTCODES[emojiData.hexcode] ?? [emojiData.label.toLowerCase().replace(/\W+/g, "_")]; const shortcodeData = SHORTCODES[emojiData.hexcode] ?? [emojiData.label.toLowerCase().replace(/\W+/g, "_")];
@ -88,7 +82,7 @@ export const EMOJI: IEmoji[] = EMOJIBASE.map((emojiData: Omit<IEmoji, "shortcode
// We manually include regional indicators in the symbols group, since // We manually include regional indicators in the symbols group, since
// Emojibase intentionally leaves them uncategorized // Emojibase intentionally leaves them uncategorized
const categoryId = const categoryId =
EMOJIBASE_GROUP_ID_TO_CATEGORY[emoji.group] ?? (isRegionalIndicator(emoji.unicode) ? "symbols" : null); EMOJIBASE_GROUP_ID_TO_CATEGORY[emoji.group!] ?? (isRegionalIndicator(emoji.unicode) ? "symbols" : null);
if (DATA_BY_CATEGORY.hasOwnProperty(categoryId)) { if (DATA_BY_CATEGORY.hasOwnProperty(categoryId)) {
DATA_BY_CATEGORY[categoryId].push(emoji); DATA_BY_CATEGORY[categoryId].push(emoji);

View file

@ -144,7 +144,12 @@ export class Mjolnir {
this.updateLists(this._roomIds); this.updateLists(this._roomIds);
}; };
private onListsChanged(settingName: string, roomId: string, atLevel: SettingLevel, newValue: string[]): void { private onListsChanged(
settingName: string,
roomId: string | null,
atLevel: SettingLevel,
newValue: string[],
): void {
// We know that ban lists are only recorded at one level so we don't need to re-eval them // We know that ban lists are only recorded at one level so we don't need to re-eval them
this.updateLists(newValue); this.updateLists(newValue);
} }

View file

@ -47,7 +47,7 @@ export default class RightPanelStore extends ReadyWatchingStore {
private static internalInstance: RightPanelStore; private static internalInstance: RightPanelStore;
private global?: IRightPanelForRoom; private global?: IRightPanelForRoom;
private byRoom: { [roomId: string]: IRightPanelForRoom }; private byRoom: { [roomId: string]: IRightPanelForRoom } = {};
private viewedRoomId: Optional<string>; private viewedRoomId: Optional<string>;
private constructor() { private constructor() {