Enable strictPropertyInitialization (#11203)

This commit is contained in:
Michael Telatynski
2023-07-07 14:46:12 +01:00
committed by GitHub
parent 4207d182cd
commit cfd48b36aa
38 changed files with 97 additions and 117 deletions

View File

@@ -43,11 +43,9 @@ export default class AutoDiscoveryUtils {
* @param {string | Error} error The error to check
* @returns {boolean} True if the error is a liveliness error.
*/
public static isLivelinessError(error?: string | Error | null): boolean {
public static isLivelinessError(error: unknown): boolean {
if (!error) return false;
return !!LIVELINESS_DISCOVERY_ERRORS.find((e) =>
typeof error === "string" ? e === error : e === error.message,
);
return !!LIVELINESS_DISCOVERY_ERRORS.find((e) => (error instanceof Error ? e === error.message : e === error));
}
/**
@@ -58,7 +56,7 @@ export default class AutoDiscoveryUtils {
* implementation for known values.
* @returns {*} The state for the component, given the error.
*/
public static authComponentStateForError(err: string | Error | null, pageName = "login"): IAuthComponentState {
public static authComponentStateForError(err: unknown, pageName = "login"): IAuthComponentState {
if (!err) {
return {
serverIsAlive: true,
@@ -93,7 +91,7 @@ export default class AutoDiscoveryUtils {
}
let isFatalError = true;
const errorMessage = typeof err === "string" ? err : err.message;
const errorMessage = err instanceof Error ? err.message : err;
if (errorMessage === AutoDiscovery.ERROR_INVALID_IDENTITY_SERVER) {
isFatalError = false;
title = _t("Cannot reach identity server");

View File

@@ -40,7 +40,7 @@ export async function doesIdentityServerHaveTerms(matrixClient: MatrixClient, fu
terms = await matrixClient.getTerms(SERVICE_TYPES.IS, fullUrl);
} catch (e) {
logger.error(e);
if (e.cors === "rejected" || (e instanceof HTTPError && e.httpStatus === 404)) {
if (e instanceof HTTPError && e.httpStatus === 404) {
terms = null;
} else {
throw e;

View File

@@ -41,8 +41,8 @@ const isGeolocationPositionError = (error: unknown): error is GeolocationPositio
/**
* Maps GeolocationPositionError to our GeolocationError enum
*/
export const mapGeolocationError = (error: GeolocationPositionError | Error): GeolocationError => {
logger.error("Geolocation failed", error?.message ?? error);
export const mapGeolocationError = (error: GeolocationPositionError | Error | unknown): GeolocationError => {
logger.error("Geolocation failed", error);
if (isGeolocationPositionError(error)) {
switch (error?.code) {
@@ -55,7 +55,7 @@ export const mapGeolocationError = (error: GeolocationPositionError | Error): Ge
default:
return GeolocationError.Default;
}
} else if (error.message === GeolocationError.Unavailable) {
} else if (error instanceof Error && error.message === GeolocationError.Unavailable) {
return GeolocationError.Unavailable;
} else {
return GeolocationError.Default;

View File

@@ -105,8 +105,10 @@ export async function leaveRoomBehaviour(
if (e instanceof MatrixError) {
const message = e.data.error || _t("Unexpected server error trying to leave the room");
results[roomId] = Object.assign(new Error(message), { errcode: e.data.errcode, data: e.data });
} else if (e instanceof Error) {
results[roomId] = e;
} else {
results[roomId] = e || new Error("Failed to leave room for unknown causes");
results[roomId] = new Error("Failed to leave room for unknown causes");
}
}
} else {

View File

@@ -41,7 +41,10 @@ export const useMap = ({ interactive, bodyId, onError }: UseMapProps): MapLibreM
try {
setMap(createMap(cli, !!interactive, bodyId, onError));
} catch (error) {
onError?.(error);
console.error("Error encountered in useMap", error);
if (error instanceof Error) {
onError?.(error);
}
}
return () => {
if (map) {