Conform more code to strictNullChecks
(#10444
* Conform more code to `strictNullChecks` * Fix tests * Fix tests
This commit is contained in:
parent
ba2608ec74
commit
c225b8ec29
29 changed files with 85 additions and 75 deletions
|
@ -33,6 +33,7 @@ interface IProps {
|
|||
|
||||
const BetaFeedbackDialog: React.FC<IProps> = ({ featureId, onFinished }) => {
|
||||
const info = SettingsStore.getBetaInfo(featureId);
|
||||
if (!info) return null;
|
||||
|
||||
return (
|
||||
<GenericFeatureFeedbackDialog
|
||||
|
|
|
@ -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());
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -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({});
|
||||
|
||||
|
|
|
@ -141,7 +141,7 @@ export default class ServerPickerDialog extends React.PureComponent<IProps, ISta
|
|||
return !error;
|
||||
},
|
||||
invalid: function ({ error }) {
|
||||
return error;
|
||||
return error ?? null;
|
||||
},
|
||||
},
|
||||
],
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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,
|
||||
});
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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)) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue