Conform more code to strictNullChecks (#10444

* Conform more code to `strictNullChecks`

* Fix tests

* Fix tests
This commit is contained in:
Michael Telatynski 2023-03-27 08:01:09 +01:00 committed by GitHub
parent ba2608ec74
commit c225b8ec29
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
29 changed files with 85 additions and 75 deletions

View file

@ -33,6 +33,7 @@ interface IProps {
const BetaFeedbackDialog: React.FC<IProps> = ({ featureId, onFinished }) => {
const info = SettingsStore.getBetaInfo(featureId);
if (!info) return null;
return (
<GenericFeatureFeedbackDialog

View file

@ -42,7 +42,7 @@ const BulkRedactDialog: React.FC<Props> = (props) => {
const { matrixClient: cli, room, member, onFinished } = props;
const [keepStateEvents, setKeepStateEvents] = useState(true);
let timeline = room.getLiveTimeline();
let timeline: EventTimeline | null = room.getLiveTimeline();
let eventsToRedact: MatrixEvent[] = [];
while (timeline) {
eventsToRedact = [
@ -93,7 +93,7 @@ const BulkRedactDialog: React.FC<Props> = (props) => {
await Promise.all(
eventsToRedact.reverse().map(async (event): Promise<void> => {
try {
await cli.redactEvent(room.roomId, event.getId());
await cli.redactEvent(room.roomId, event.getId()!);
} catch (err) {
// log and swallow errors
logger.error("Could not redact", event.getId());

View file

@ -71,7 +71,7 @@ interface IProps {
type ToolInfo = [label: string, tool: Tool];
const DevtoolsDialog: React.FC<IProps> = ({ roomId, onFinished }) => {
const [tool, setTool] = useState<ToolInfo>(null);
const [tool, setTool] = useState<ToolInfo | null>(null);
let body: JSX.Element;
let onBack: () => void;

View file

@ -51,6 +51,7 @@ import { ButtonEvent } from "../elements/AccessibleButton";
import { isLocationEvent } from "../../../utils/EventUtils";
import { isSelfLocation, locationEventGeoUri } from "../../../utils/location";
import { RoomContextDetails } from "../rooms/RoomContextDetails";
import { filterBoolean } from "../../../utils/arrays";
const AVATAR_SIZE = 30;
@ -194,7 +195,7 @@ const transformEvent = (event: MatrixEvent): { type: string; content: IContent }
};
const ForwardDialog: React.FC<IProps> = ({ matrixClient: cli, event, permalinkCreator, onFinished }) => {
const userId = cli.getUserId();
const userId = cli.getSafeUserId();
const [profileInfo, setProfileInfo] = useState<any>({});
useEffect(() => {
cli.getProfileInfo(userId).then((info) => setProfileInfo(info));
@ -242,7 +243,7 @@ const ForwardDialog: React.FC<IProps> = ({ matrixClient: cli, event, permalinkCr
if (lcQuery) {
rooms = new QueryMatcher<Room>(rooms, {
keys: ["name"],
funcs: [(r) => [r.getCanonicalAlias(), ...r.getAltAliases()].filter(Boolean)],
funcs: [(r) => filterBoolean([r.getCanonicalAlias(), ...r.getAltAliases()])],
shouldMatchWordsOnly: false,
}).match(lcQuery);
}

View file

@ -34,6 +34,7 @@ const RegistrationEmailPromptDialog: React.FC<IProps> = ({ onFinished }) => {
const onSubmit = async (e: SyntheticEvent): Promise<void> => {
e.preventDefault();
if (!fieldRef.current) return;
if (email) {
const valid = await fieldRef.current.validate({});

View file

@ -141,7 +141,7 @@ export default class ServerPickerDialog extends React.PureComponent<IProps, ISta
return !error;
},
invalid: function ({ error }) {
return error;
return error ?? null;
},
},
],

View file

@ -49,7 +49,7 @@ interface ITermsDialogProps {
/**
* urls that the user has already agreed to
*/
agreedUrls?: string[];
agreedUrls: string[];
/**
* Called with:
@ -127,7 +127,7 @@ export default class TermsDialog extends React.PureComponent<ITermsDialogProps,
};
public render(): React.ReactNode {
const rows = [];
const rows: JSX.Element[] = [];
for (const policiesAndService of this.props.policiesAndServicePairs) {
const parsedBaseUrl = url.parse(policiesAndService.service.baseUrl);
@ -135,8 +135,8 @@ export default class TermsDialog extends React.PureComponent<ITermsDialogProps,
for (let i = 0; i < policyValues.length; ++i) {
const termDoc = policyValues[i];
const termsLang = pickBestLanguage(Object.keys(termDoc).filter((k) => k !== "version"));
let serviceName;
let summary;
let serviceName: JSX.Element | undefined;
let summary: JSX.Element | undefined;
if (i === 0) {
serviceName = this.nameForServiceType(policiesAndService.service.serviceType, parsedBaseUrl.host);
summary = this.summaryForServiceType(policiesAndService.service.serviceType);

View file

@ -100,7 +100,7 @@ export default class TextInputDialog extends React.Component<IProps, IState> {
};
private onValidate = async (fieldState: IFieldState): Promise<IValidationResult> => {
const result = await this.props.validator(fieldState);
const result = await this.props.validator!(fieldState);
this.setState({
valid: !!result.valid,
});

View file

@ -38,7 +38,7 @@ export function RoomResultContextMenus({ room }: Props): JSX.Element {
const [generalMenuPosition, setGeneralMenuPosition] = useState<DOMRect | null>(null);
const [notificationMenuPosition, setNotificationMenuPosition] = useState<DOMRect | null>(null);
let generalMenu: JSX.Element;
let generalMenu: JSX.Element | undefined;
if (generalMenuPosition !== null) {
if (room.isSpaceRoom()) {
generalMenu = (
@ -59,7 +59,7 @@ export function RoomResultContextMenus({ room }: Props): JSX.Element {
}
}
let notificationMenu: JSX.Element;
let notificationMenu: JSX.Element | undefined;
if (notificationMenuPosition !== null) {
notificationMenu = (
<RoomNotificationContextMenu

View file

@ -440,7 +440,7 @@ const SpotlightDialog: React.FC<IProps> = ({ initialText = "", initialFilter = n
// Sort results by most recent activity
const myUserId = cli.getUserId();
const myUserId = cli.getSafeUserId();
for (const resultArray of Object.values(results)) {
resultArray.sort((a: Result, b: Result) => {
if (isRoomResult(a) || isRoomResult(b)) {