Conform more of the codebase to strictNullChecks (#10800)

This commit is contained in:
Michael Telatynski 2023-05-10 08:41:55 +01:00 committed by GitHub
parent adb29b38a3
commit 456c66db5b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
46 changed files with 147 additions and 123 deletions

View file

@ -19,7 +19,7 @@ import React, { ChangeEvent } from "react";
import { MatrixEvent } from "matrix-js-sdk/src/models/event";
import { logger } from "matrix-js-sdk/src/logger";
import { _t } from "../../../languageHandler";
import { _t, UserFriendlyError } from "../../../languageHandler";
import { ensureDMExists } from "../../../createRoom";
import { MatrixClientPeg } from "../../../MatrixClientPeg";
import SdkConfig from "../../../SdkConfig";
@ -245,6 +245,10 @@ export default class ReportEventDialog extends React.Component<IProps, IState> {
// Report to moderators through to the dedicated bot,
// as configured in the room's state events.
const dmRoomId = await ensureDMExists(client, this.moderation.moderationBotUserId);
if (!dmRoomId) {
throw new UserFriendlyError("Unable to create room with moderation bot");
}
await client.sendEvent(dmRoomId, ABUSE_EVENT_TYPE, {
event_id: ev.getId(),
room_id: ev.getRoomId(),

View file

@ -62,7 +62,7 @@ interface IState {
}
class RoomSettingsDialog extends React.Component<IProps, IState> {
private dispatcherRef: string;
private dispatcherRef?: string;
public constructor(props: IProps) {
super(props);

View file

@ -35,7 +35,7 @@ interface IState {
}
export default class RoomUpgradeDialog extends React.Component<IProps, IState> {
private targetVersion: string;
private targetVersion?: string;
public state = {
busy: true,
@ -53,7 +53,7 @@ export default class RoomUpgradeDialog extends React.Component<IProps, IState> {
private onUpgradeClick = (): void => {
this.setState({ busy: true });
upgradeRoom(this.props.room, this.targetVersion, false, false)
upgradeRoom(this.props.room, this.targetVersion!, false, false)
.then(() => {
this.props.onFinished(true);
})
@ -69,7 +69,7 @@ export default class RoomUpgradeDialog extends React.Component<IProps, IState> {
};
public render(): React.ReactNode {
let buttons;
let buttons: JSX.Element;
if (this.state.busy) {
buttons = <Spinner />;
} else {

View file

@ -44,7 +44,7 @@ interface IState {
export default class ServerPickerDialog extends React.PureComponent<IProps, IState> {
private readonly defaultServer: ValidatedServerConfig;
private readonly fieldRef = createRef<Field>();
private validatedConf: ValidatedServerConfig;
private validatedConf?: ValidatedServerConfig;
public constructor(props: IProps) {
super(props);
@ -85,7 +85,7 @@ export default class ServerPickerDialog extends React.PureComponent<IProps, ISta
// find their homeserver without demanding they use "https://matrix.org"
private validate = withValidation<this, { error?: string }>({
deriveData: async ({ value }): Promise<{ error?: string }> => {
let hsUrl = value.trim(); // trim to account for random whitespace
let hsUrl = (value ?? "").trim(); // trim to account for random whitespace
// if the URL has no protocol, try validate it as a serverName via well-known
if (!hsUrl.includes("://")) {

View file

@ -45,7 +45,7 @@ interface IState {
* On success, `onFinished(true)` is called.
*/
export default class SetEmailDialog extends React.Component<IProps, IState> {
private addThreepid: AddThreepid;
private addThreepid?: AddThreepid;
public constructor(props: IProps) {
super(props);
@ -109,7 +109,7 @@ export default class SetEmailDialog extends React.Component<IProps, IState> {
};
private verifyEmailAddress(): void {
this.addThreepid.checkEmailLinkClicked().then(
this.addThreepid?.checkEmailLinkClicked().then(
() => {
this.props.onFinished(true);
},