Skip to content
This repository has been archived by the owner on Sep 11, 2024. It is now read-only.

Commit

Permalink
Enable strictPropertyInitialization (#11203)
Browse files Browse the repository at this point in the history
  • Loading branch information
t3chguy authored Jul 7, 2023
1 parent 4207d18 commit cfd48b3
Show file tree
Hide file tree
Showing 38 changed files with 97 additions and 117 deletions.
40 changes: 0 additions & 40 deletions .github/workflows/static_analysis.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -43,46 +43,6 @@ jobs:
- name: Typecheck (release mode)
run: "yarn run lint:types"

tsc-strict:
name: Typescript Strict Error Checker
if: github.event_name == 'pull_request'
runs-on: ubuntu-latest
permissions:
pull-requests: read
checks: write
steps:
- uses: actions/checkout@v3
with:
ref: ${{ github.event.pull_request.head.sha }}

- name: Install Deps
run: "scripts/ci/layered.sh"

- name: Get diff lines
id: diff
uses: Equip-Collaboration/diff-line-numbers@e752977e2cb4207d671bb9e4dad18c07c1b73d52 # v1.1.0
with:
include: '["\\.tsx?$"]'

- name: Detecting files changed
id: files
uses: futuratrepadeira/changed-files@0239328a3a6268aad16af7c3e4efc78e32d6c0f0 # v4.0.1
with:
repo-token: ${{ secrets.GITHUB_TOKEN }}
pattern: '^.*\.tsx?$'

- uses: t3chguy/typescript-check-action@main
with:
repo-token: ${{ secrets.GITHUB_TOKEN }}
use-check: false
check-fail-mode: added
output-behaviour: annotate
ts-extra-args: "--strict --noImplicitAny"
files-changed: ${{ steps.files.outputs.files_updated }}
files-added: ${{ steps.files.outputs.files_created }}
files-deleted: ${{ steps.files.outputs.files_deleted }}
line-numbers: ${{ steps.diff.outputs.lineNumbers }}

i18n_lint:
name: "i18n Check"
uses: matrix-org/matrix-react-sdk/.github/workflows/i18n_check.yml@develop
Expand Down
2 changes: 1 addition & 1 deletion src/Lifecycle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -497,7 +497,7 @@ export async function restoreFromLocalStorage(opts?: { ignoreGuest?: boolean }):
}
}

async function handleLoadSessionFailure(e: Error): Promise<boolean> {
async function handleLoadSessionFailure(e: unknown): Promise<boolean> {
logger.error("Unable to load session", e);

const modal = Modal.createDialog(SessionRestoreErrorDialog, {
Expand Down
2 changes: 1 addition & 1 deletion src/PosthogAnalytics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -324,7 +324,7 @@ export class PosthogAnalytics {
} catch (e) {
// The above could fail due to network requests, but not essential to starting the application,
// so swallow it.
logger.log("Unable to identify user for tracking" + e.toString());
logger.log("Unable to identify user for tracking", e);
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/components/views/auth/CaptchaForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ export default class CaptchaForm extends React.Component<ICaptchaFormProps, ICap
});
} catch (e) {
this.setState({
errorText: e.toString(),
errorText: e instanceof Error ? e.message : String(e),
});
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -647,7 +647,7 @@ export class MsisdnAuthEntry extends React.Component<IMsisdnAuthEntryProps, IMsi
});
}
} catch (e) {
this.props.fail(e);
this.props.fail(e instanceof Error ? e : new Error("Failed to submit msisdn token"));
logger.log("Failed to submit msisdn token");
}
};
Expand Down
6 changes: 4 additions & 2 deletions src/components/views/beacon/BeaconViewDialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ const BeaconViewDialog: React.FC<IProps> = ({ initialFocusedBeacon, roomId, matr

const { bounds, centerGeoUri } = useMapPosition(liveBeacons, focusedBeaconState);

const [mapDisplayError, setMapDisplayError] = useState<Error>();
const [mapDisplayError, setMapDisplayError] = useState<unknown>();

// automatically open the sidebar if there is no map to see
useEffect(() => {
Expand Down Expand Up @@ -156,7 +156,9 @@ const BeaconViewDialog: React.FC<IProps> = ({ initialFocusedBeacon, roomId, matr
)}
</Map>
)}
{mapDisplayError && <MapError error={mapDisplayError.message as LocationShareError} isMinimised />}
{mapDisplayError instanceof Error && (
<MapError error={mapDisplayError.message as LocationShareError} isMinimised />
)}
{!centerGeoUri && !mapDisplayError && (
<MapFallback data-testid="beacon-view-dialog-map-fallback" className="mx_BeaconViewDialog_map">
<span className="mx_BeaconViewDialog_mapFallbackMessage">{_t("No live locations")}</span>
Expand Down
8 changes: 4 additions & 4 deletions src/components/views/dialogs/AddExistingToSpaceDialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ export const AddExistingToSpace: React.FC<IAddExistingToSpaceProps> = ({

const [selectedToAdd, setSelectedToAdd] = useState(new Set<Room>());
const [progress, setProgress] = useState<number | null>(null);
const [error, setError] = useState<Error | null>(null);
const [error, setError] = useState(false);
const [query, setQuery] = useState("");
const lcQuery = query.toLowerCase().trim();

Expand Down Expand Up @@ -196,10 +196,10 @@ export const AddExistingToSpace: React.FC<IAddExistingToSpaceProps> = ({
}, [visibleRooms, space, lcQuery, existingRoomsSet, existingSubspacesSet]);

const addRooms = async (): Promise<void> => {
setError(null);
setError(false);
setProgress(0);

let error: Error | undefined;
let error = false;

for (const room of selectedToAdd) {
const via = calculateRoomVia(room);
Expand All @@ -216,7 +216,7 @@ export const AddExistingToSpace: React.FC<IAddExistingToSpaceProps> = ({
setProgress((i) => (i ?? 0) + 1);
} catch (e) {
logger.error("Failed to add rooms to space", e);
error = e;
error = true;
break;
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/components/views/dialogs/BugReportDialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ interface IProps {
onFinished: (success: boolean) => void;
initialText?: string;
label?: string;
error?: Error;
error?: unknown;
}

interface IState {
Expand Down
2 changes: 1 addition & 1 deletion src/components/views/dialogs/SessionRestoreErrorDialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import BaseDialog from "./BaseDialog";
import DialogButtons from "../elements/DialogButtons";

interface IProps {
error: Error;
error: unknown;
onFinished(clear?: boolean): void;
}

Expand Down
6 changes: 3 additions & 3 deletions src/components/views/dialogs/SlidingSyncOptionsDialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,8 @@ export const SlidingSyncOptionsDialog: React.FC<{ onFinished(enabled: boolean):
: _t("Your server lacks native support");
}

const validProxy = withValidation<undefined, { error?: Error }>({
async deriveData({ value }): Promise<{ error?: Error }> {
const validProxy = withValidation<undefined, { error?: unknown }>({
async deriveData({ value }): Promise<{ error?: unknown }> {
try {
await proxyHealthCheck(value!, MatrixClientPeg.safeGet().baseUrl);
return {};
Expand All @@ -104,7 +104,7 @@ export const SlidingSyncOptionsDialog: React.FC<{ onFinished(enabled: boolean):
final: true,
test: async (_, { error }) => !error,
valid: () => _t("Looks good"),
invalid: ({ error }) => error?.message ?? null,
invalid: ({ error }) => (error instanceof Error ? error.message : null),
},
],
});
Expand Down
2 changes: 1 addition & 1 deletion src/components/views/dialogs/devtools/Event.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ export const EventEditor: React.FC<IEventEditorProps> = ({ fieldDefs, defaultCon
const json = JSON.parse(content);
await onSend(fieldData, json);
} catch (e) {
return _t("Failed to send event!") + ` (${e.toString()})`;
return _t("Failed to send event!") + (e instanceof Error ? ` (${e.message})` : "");
}
return _t("Event sent!");
};
Expand Down
2 changes: 1 addition & 1 deletion src/components/views/dialogs/devtools/SettingExplorer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ const EditSetting: React.FC<IEditSettingProps> = ({ setting, onBack }) => {
}
onBack();
} catch (e) {
return _t("Failed to save settings.") + ` (${e.message})`;
return _t("Failed to save settings.") + (e instanceof Error ? ` (${e.message})` : "");
}
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ interface IProps {
}

interface IState {
error: Error | null;
error: boolean;
canUploadKeysWithPasswordOnly: boolean | null;
accountPassword: string;
}
Expand All @@ -52,7 +52,7 @@ export default class CreateCrossSigningDialog extends React.PureComponent<IProps
super(props);

this.state = {
error: null,
error: false,
// Does the server offer a UI auth flow with just m.login.password
// for /keys/device_signing/upload?
// If we have an account password in memory, let's simplify and
Expand Down Expand Up @@ -145,7 +145,7 @@ export default class CreateCrossSigningDialog extends React.PureComponent<IProps

private bootstrapCrossSigning = async (): Promise<void> => {
this.setState({
error: null,
error: false,
});

try {
Expand All @@ -161,7 +161,7 @@ export default class CreateCrossSigningDialog extends React.PureComponent<IProps
return;
}

this.setState({ error: e });
this.setState({ error: true });
logger.error("Error bootstrapping cross-signing", e);
}
};
Expand Down
10 changes: 6 additions & 4 deletions src/components/views/dialogs/security/RestoreKeyBackupDialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import { MatrixClient } from "matrix-js-sdk/src/client";
import { IKeyBackupInfo, IKeyBackupRestoreResult } from "matrix-js-sdk/src/crypto/keybackup";
import { ISecretStorageKeyInfo } from "matrix-js-sdk/src/crypto/api";
import { logger } from "matrix-js-sdk/src/logger";
import { MatrixError } from "matrix-js-sdk/src/matrix";

import { MatrixClientPeg } from "../../../../MatrixClientPeg";
import { _t } from "../../../../languageHandler";
Expand Down Expand Up @@ -56,9 +57,7 @@ interface IState {
backupKeyStored: Record<string, ISecretStorageKeyInfo> | null;
loading: boolean;
loadError: boolean | null;
restoreError: {
errcode: string;
} | null;
restoreError: unknown | null;
recoveryKey: string;
recoverInfo: IKeyBackupRestoreResult | null;
recoveryKeyValid: boolean;
Expand Down Expand Up @@ -343,7 +342,10 @@ export default class RestoreKeyBackupDialog extends React.PureComponent<IProps,
title = _t("Error");
content = _t("Unable to load backup status");
} else if (this.state.restoreError) {
if (this.state.restoreError.errcode === MatrixClient.RESTORE_BACKUP_ERROR_BAD_KEY) {
if (
this.state.restoreError instanceof MatrixError &&
this.state.restoreError.errcode === MatrixClient.RESTORE_BACKUP_ERROR_BAD_KEY
) {
if (this.state.restoreType === RestoreType.RecoveryKey) {
title = _t("Security Key mismatch");
content = (
Expand Down
6 changes: 3 additions & 3 deletions src/components/views/directory/NetworkDropdown.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ export interface IPublicRoomDirectoryConfig {
instanceId?: string;
}

const validServer = withValidation<undefined, { error?: MatrixError }>({
deriveData: async ({ value }): Promise<{ error?: MatrixError }> => {
const validServer = withValidation<undefined, { error?: unknown }>({
deriveData: async ({ value }): Promise<{ error?: unknown }> => {
try {
// check if we can successfully load this server's room directory
await MatrixClientPeg.safeGet().publicRooms({
Expand All @@ -63,7 +63,7 @@ const validServer = withValidation<undefined, { error?: MatrixError }>({
test: async (_, { error }) => !error,
valid: () => _t("Looks good"),
invalid: ({ error }) =>
error?.errcode === "M_FORBIDDEN"
error instanceof MatrixError && error.errcode === "M_FORBIDDEN"
? _t("You are not allowed to view this server's rooms list")
: _t("Can't find this server or its room list"),
},
Expand Down
2 changes: 1 addition & 1 deletion src/components/views/elements/EditableTextContainer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ export default class EditableTextContainer extends React.Component<IProps, IStat
} catch (error) {
if (this.unmounted) return;
this.setState({
errorString: error.toString(),
errorString: error instanceof Error ? error.message : String(error),
busy: false,
});
}
Expand Down
6 changes: 3 additions & 3 deletions src/components/views/messages/MAudioBody.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ import RoomContext, { TimelineRenderingType } from "../../../contexts/RoomContex
import MediaProcessingError from "./shared/MediaProcessingError";

interface IState {
error?: Error;
error?: boolean;
playback?: Playback;
}

Expand All @@ -54,12 +54,12 @@ export default class MAudioBody extends React.PureComponent<IBodyProps, IState>
const blob = await this.props.mediaEventHelper!.sourceBlob.value;
buffer = await blob.arrayBuffer();
} catch (e) {
this.setState({ error: e });
this.setState({ error: true });
logger.warn("Unable to decrypt audio message", e);
return; // stop processing the audio file
}
} catch (e) {
this.setState({ error: e });
this.setState({ error: true });
logger.warn("Unable to decrypt/download audio message", e);
return; // stop processing the audio file
}
Expand Down
2 changes: 1 addition & 1 deletion src/components/views/messages/MImageBody.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ interface IState {
contentUrl: string | null;
thumbUrl: string | null;
isAnimated?: boolean;
error?: Error;
error?: unknown;
imgError: boolean;
imgLoaded: boolean;
loadedImageDimensions?: {
Expand Down
10 changes: 6 additions & 4 deletions src/components/views/settings/CrossSigningPanel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ import AccessibleButton from "../elements/AccessibleButton";
import { SettingsSubsectionText } from "./shared/SettingsSubsection";

interface IState {
error?: Error;
error: boolean;
crossSigningPublicKeysOnDevice?: boolean;
crossSigningPrivateKeysInStorage?: boolean;
masterPrivateKeyCached?: boolean;
Expand All @@ -47,7 +47,9 @@ export default class CrossSigningPanel extends React.PureComponent<{}, IState> {
public constructor(props: {}) {
super(props);

this.state = {};
this.state = {
error: false,
};
}

public componentDidMount(): void {
Expand Down Expand Up @@ -125,7 +127,7 @@ export default class CrossSigningPanel extends React.PureComponent<{}, IState> {
* @param {bool} [forceReset] Bootstrap again even if keys already present
*/
private bootstrapCrossSigning = async ({ forceReset = false }): Promise<void> => {
this.setState({ error: undefined });
this.setState({ error: false });
try {
const cli = MatrixClientPeg.safeGet();
await cli.bootstrapCrossSigning({
Expand All @@ -143,7 +145,7 @@ export default class CrossSigningPanel extends React.PureComponent<{}, IState> {
setupNewCrossSigning: forceReset,
});
} catch (e) {
this.setState({ error: e });
this.setState({ error: true });
logger.error("Error bootstrapping cross-signing", e);
}
if (this.unmounted) return;
Expand Down
6 changes: 5 additions & 1 deletion src/components/views/settings/EventIndexPanel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,11 @@ export default class EventIndexPanel extends React.Component<{}, IState> {
<SettingsSubsectionText>
<details>
<summary>{_t("Advanced")}</summary>
<code>{EventIndexPeg.error.message}</code>
<code>
{EventIndexPeg.error instanceof Error
? EventIndexPeg.error.message
: _t("Unknown error")}
</code>
<p>
<AccessibleButton key="delete" kind="danger" onClick={this.confirmEventStoreReset}>
{_t("Reset")}
Expand Down
2 changes: 1 addition & 1 deletion src/components/views/settings/JoinRuleSettings.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ export interface JoinRuleSettingsProps {
room: Room;
promptUpgrade?: boolean;
closeSettingsFn(): void;
onError(error: Error): void;
onError(error: unknown): void;
beforeChange?(joinRule: JoinRule): Promise<boolean>; // if returns false then aborts the change
aliasWarning?: ReactNode;
}
Expand Down
Loading

0 comments on commit cfd48b3

Please sign in to comment.