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

This commit is contained in:
Michael Telatynski 2023-07-05 11:53:22 +01:00 committed by GitHub
parent 4044c2aa66
commit 8107f1d271
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
25 changed files with 88 additions and 57 deletions

View file

@ -246,11 +246,11 @@ export default class Registration extends React.Component<IProps, IState> {
}
} catch (e) {
if (serverConfig !== this.latestServerConfig) return; // discard, serverConfig changed from under us
if (e.httpStatus === 401) {
if (e instanceof MatrixError && e.httpStatus === 401) {
this.setState({
flows: e.data.flows,
});
} else if (e.httpStatus === 403 || e.errcode === "M_FORBIDDEN") {
} else if (e instanceof MatrixError && (e.httpStatus === 403 || e.errcode === "M_FORBIDDEN")) {
// Check for 403 or M_FORBIDDEN, Synapse used to send 403 M_UNKNOWN but now sends 403 M_FORBIDDEN.
// At this point registration is pretty much disabled, but before we do that let's
// quickly check to see if the server supports SSO instead. If it does, we'll send

View file

@ -60,7 +60,7 @@ export default class ChangelogDialog extends React.Component<IProps, State> {
const body = await res.json();
this.setState({ [repo]: body.commits });
} catch (err) {
this.setState({ [repo]: err.message });
this.setState({ [repo]: err instanceof Error ? err.message : _t("Unknown error") });
}
}

View file

@ -39,7 +39,6 @@ interface IState {
shouldLoadBackupStatus: boolean;
loading: boolean;
backupInfo: IKeyBackupInfo | null;
error?: string;
}
export default class LogoutDialog extends React.Component<IProps, IState> {
@ -75,7 +74,6 @@ export default class LogoutDialog extends React.Component<IProps, IState> {
logger.log("Unable to fetch key backup status", e);
this.setState({
loading: false,
error: e,
});
}
}

View file

@ -272,7 +272,7 @@ export default class ReportEventDialog extends React.Component<IProps, IState> {
logger.error(e);
this.setState({
busy: false,
err: e.message,
err: e instanceof Error ? e.message : String(e),
});
}
};

View file

@ -18,7 +18,8 @@ limitations under the License.
import React from "react";
import { CrossSigningKeys } from "matrix-js-sdk/src/client";
import { logger } from "matrix-js-sdk/src/logger";
import { UIAFlow } from "matrix-js-sdk/src/matrix";
import { AuthDict, MatrixError, UIAFlow } from "matrix-js-sdk/src/matrix";
import { UIAResponse } from "matrix-js-sdk/src/@types/uia";
import { MatrixClientPeg } from "../../../../MatrixClientPeg";
import { _t } from "../../../../languageHandler";
@ -79,7 +80,7 @@ export default class CreateCrossSigningDialog extends React.PureComponent<IProps
// no keys which would be a no-op.
logger.log("uploadDeviceSigningKeys unexpectedly succeeded without UI auth!");
} catch (error) {
if (!error.data || !error.data.flows) {
if (!(error instanceof MatrixError) || !error.data || !error.data.flows) {
logger.log("uploadDeviceSigningKeys advertised no flows!");
return;
}
@ -92,7 +93,9 @@ export default class CreateCrossSigningDialog extends React.PureComponent<IProps
}
}
private doBootstrapUIAuth = async (makeRequest: (authData: any) => Promise<{}>): Promise<void> => {
private doBootstrapUIAuth = async (
makeRequest: (authData: AuthDict) => Promise<UIAResponse<void>>,
): Promise<void> => {
if (this.state.canUploadKeysWithPasswordOnly && this.state.accountPassword) {
await makeRequest({
type: "m.login.password",

View file

@ -55,7 +55,7 @@ interface IState {
backupInfo: IKeyBackupInfo | null;
backupKeyStored: Record<string, ISecretStorageKeyInfo> | null;
loading: boolean;
loadError: string | null;
loadError: boolean | null;
restoreError: {
errcode: string;
} | null;
@ -66,7 +66,7 @@ interface IState {
passPhrase: string;
restoreType: RestoreType | null;
progress: {
stage: ProgressState;
stage: ProgressState | string;
total?: number;
successes?: number;
failures?: number;
@ -304,7 +304,7 @@ export default class RestoreKeyBackupDialog extends React.PureComponent<IProps,
} catch (e) {
logger.log("Error loading backup status", e);
this.setState({
loadError: e,
loadError: true,
loading: false,
});
}

View file

@ -92,7 +92,7 @@ export default class LazyRenderList<T = any> extends React.Component<IProps<T>,
this.state = LazyRenderList.getDerivedStateFromProps(props, {} as IState) as IState;
}
public static getDerivedStateFromProps(props: IProps<unknown>, state: IState): Partial<IState> | null {
public static getDerivedStateFromProps<T>(props: IProps<T>, state: IState): Partial<IState> | null {
const range = LazyRenderList.getVisibleRangeFromProps(props);
const intersectRange = range.expand(props.overflowMargin);
const renderRange = range.expand(props.overflowItems);
@ -105,7 +105,7 @@ export default class LazyRenderList<T = any> extends React.Component<IProps<T>,
return null;
}
private static getVisibleRangeFromProps(props: IProps<unknown>): ItemRange {
private static getVisibleRangeFromProps<T>(props: IProps<T>): ItemRange {
const { items, itemHeight, scrollTop, height } = props;
const length = items ? items.length : 0;
const topCount = Math.min(Math.max(0, Math.floor(scrollTop / itemHeight)), length);

View file

@ -15,6 +15,7 @@ limitations under the License.
*/
import React, { createRef, KeyboardEventHandler } from "react";
import { MatrixError } from "matrix-js-sdk/src/matrix";
import { _t } from "../../../languageHandler";
import withValidation, { IFieldState, IValidationResult } from "./Validation";
@ -209,7 +210,7 @@ export default class RoomAliasField extends React.PureComponent<IProps, IState>
// any server error code will do,
// either it M_NOT_FOUND or the alias is invalid somehow,
// in which case we don't want to show the invalid message
return !!err.errcode;
return err instanceof MatrixError;
}
},
valid: () => _t("This address is available to use"),

View file

@ -14,7 +14,7 @@ See the License for the specific language governing permissions and
limitations under the License.
*/
import { MatrixClient } from "matrix-js-sdk/src/matrix";
import { MatrixClient, MatrixError } from "matrix-js-sdk/src/matrix";
import { IAuthDict, IAuthData } from "matrix-js-sdk/src/interactive-auth";
import { _t } from "../../../../languageHandler";
@ -42,7 +42,7 @@ export const deleteDevicesWithInteractiveAuth = async (
// no interactive auth needed
onFinished(true, undefined);
} catch (error) {
if (error.httpStatus !== 401 || !error.data?.flows) {
if (!(error instanceof MatrixError) || error.httpStatus !== 401 || !error.data?.flows) {
// doesn't look like an interactive-auth failure
throw error;
}
@ -73,7 +73,7 @@ export const deleteDevicesWithInteractiveAuth = async (
Modal.createDialog(InteractiveAuthDialog, {
title: _t("Authentication"),
matrixClient: matrixClient,
authData: error.data,
authData: error.data as IAuthData,
onFinished,
makeRequest: makeDeleteRequest(matrixClient, deviceIds),
aestheticsForStagePhases: {

View file

@ -147,7 +147,7 @@ export default class VerificationRequestToast extends React.PureComponent<IProps
}
await request.accept();
} catch (err) {
logger.error(err.message);
logger.error("Failed to accept verification request", err);
}
};