From a3a0d7fefbf6eb923c5ff797fda42fda1ddfb5cc Mon Sep 17 00:00:00 2001 From: Michael Telatynski <7t3chguy@gmail.com> Date: Mon, 13 Mar 2023 11:10:40 +0000 Subject: [PATCH 1/4] Conform more of the codebase to `strictNullChecks` --- .../context_menus/MessageContextMenu.tsx | 50 +++++++++---------- .../views/elements/AccessibleButton.tsx | 5 +- .../views/elements/AppPermission.tsx | 2 - .../elements/DesktopCapturerSourcePicker.tsx | 3 +- .../views/elements/DialogButtons.tsx | 8 +-- src/components/views/elements/Dropdown.tsx | 16 +++--- .../views/elements/EffectsOverlay.tsx | 6 +-- .../views/elements/ErrorBoundary.tsx | 10 ++-- .../views/elements/EventListSummary.tsx | 4 +- src/components/views/elements/Field.tsx | 4 +- .../elements/GenericEventListSummary.tsx | 2 +- .../elements/IRCTimelineProfileResizer.tsx | 4 +- src/components/views/elements/ImageView.tsx | 24 ++++----- .../views/elements/InteractiveTooltip.tsx | 16 +++--- .../views/elements/LanguageDropdown.tsx | 6 +-- .../views/elements/LazyRenderList.tsx | 4 +- .../views/elements/MiniAvatarUploader.tsx | 3 +- .../views/elements/PersistentApp.tsx | 2 +- .../views/elements/PollCreateDialog.tsx | 7 ++- src/components/views/elements/ReplyChain.tsx | 2 +- .../views/elements/RoomAliasField.tsx | 9 ++-- src/components/views/elements/RoomTopic.tsx | 4 +- .../views/elements/SearchWarning.tsx | 2 +- .../views/elements/ServerPicker.tsx | 2 +- .../views/elements/SettingsFlag.tsx | 4 +- .../elements/SpellCheckLanguagesDropdown.tsx | 13 +++-- .../views/elements/TextWithTooltip.tsx | 2 +- .../views/elements/UseCaseSelection.tsx | 2 +- .../views/elements/UseCaseSelectionButton.tsx | 2 +- src/components/views/elements/Validation.tsx | 2 +- .../views/messages/DownloadActionButton.tsx | 2 +- .../views/messages/EditHistoryMessage.tsx | 17 +++---- .../views/messages/JumpToDatePicker.tsx | 2 +- .../views/messages/LegacyCallEvent.tsx | 2 +- src/components/views/messages/MBeaconBody.tsx | 6 +-- src/components/views/messages/MImageBody.tsx | 32 ++++++------ .../views/messages/MJitsiWidgetEvent.tsx | 2 +- .../messages/MKeyVerificationRequest.tsx | 2 +- .../views/messages/MLocationBody.tsx | 13 +++-- src/components/views/messages/MPollBody.tsx | 2 +- .../views/messages/MStickerBody.tsx | 12 ++--- src/components/views/messages/MVideoBody.tsx | 24 ++++----- .../views/messages/MessageActionBar.tsx | 24 ++++----- .../views/messages/MessageEvent.tsx | 8 +-- .../views/messages/ReactionsRow.tsx | 4 +- .../views/messages/ReactionsRowButton.tsx | 2 +- .../views/messages/SenderProfile.tsx | 4 +- src/components/views/messages/TextualBody.tsx | 39 ++++++++------- .../views/messages/TileErrorBoundary.tsx | 6 +-- src/components/views/rooms/Autocomplete.tsx | 4 +- .../views/rooms/BasicMessageComposer.tsx | 18 +++---- src/components/views/rooms/E2EIcon.tsx | 6 +-- .../views/rooms/EditMessageComposer.tsx | 9 ++-- src/components/views/rooms/EntityTile.tsx | 12 ++--- src/components/views/rooms/EventTile.tsx | 40 +++++++-------- src/components/views/rooms/HistoryTile.tsx | 8 +-- .../views/rooms/LinkPreviewGroup.tsx | 4 +- .../views/rooms/LinkPreviewWidget.tsx | 8 +-- src/components/views/rooms/MemberList.tsx | 6 ++- src/components/views/rooms/MemberTile.tsx | 7 ++- .../views/rooms/MessageComposerButtons.tsx | 8 +-- src/components/views/rooms/NewRoomIntro.tsx | 14 +++--- .../views/rooms/NotificationBadge.tsx | 10 ++-- .../views/rooms/ReadReceiptGroup.tsx | 10 ++-- .../views/rooms/ReadReceiptMarker.tsx | 2 +- src/components/views/rooms/RoomPreviewBar.tsx | 9 ++-- src/components/views/rooms/RoomTile.tsx | 2 +- src/events/EventTileFactory.tsx | 4 +- src/settings/SettingsStore.ts | 2 +- src/utils/EventUtils.ts | 2 +- 70 files changed, 302 insertions(+), 306 deletions(-) diff --git a/src/components/views/context_menus/MessageContextMenu.tsx b/src/components/views/context_menus/MessageContextMenu.tsx index ad56409592c..8392e6a14fd 100644 --- a/src/components/views/context_menus/MessageContextMenu.tsx +++ b/src/components/views/context_menus/MessageContextMenu.tsx @@ -179,7 +179,7 @@ export default class MessageContextMenu extends React.Component private isPinned(): boolean { const room = MatrixClientPeg.get().getRoom(this.props.mxEvent.getRoomId()); - const pinnedEvent = room.currentState.getStateEvents(EventType.RoomPinnedEvents, ""); + const pinnedEvent = room?.currentState.getStateEvents(EventType.RoomPinnedEvents, ""); if (!pinnedEvent) return false; const content = pinnedEvent.getContent(); return content.pinned && Array.isArray(content.pinned) && content.pinned.includes(this.props.mxEvent.getId()); @@ -389,7 +389,7 @@ export default class MessageContextMenu extends React.Component timelineRenderingType === TimelineRenderingType.ThreadsList; const isThreadRootEvent = isThread && mxEvent?.getThread()?.rootEvent === mxEvent; - let resendReactionsButton: JSX.Element; + let resendReactionsButton: JSX.Element | undefined; if (!mxEvent.isRedacted() && unsentReactionsCount !== 0) { resendReactionsButton = ( ); } - let redactButton: JSX.Element; + let redactButton: JSX.Element | undefined; if (isSent && this.state.canRedact) { redactButton = ( ); } - let openInMapSiteButton: JSX.Element; + let openInMapSiteButton: JSX.Element | undefined; const shareableLocationEvent = getShareableLocationEvent(mxEvent, cli); if (shareableLocationEvent) { const mapSiteLink = createMapSiteLinkFromEvent(shareableLocationEvent); @@ -430,7 +430,7 @@ export default class MessageContextMenu extends React.Component ); } - let forwardButton: JSX.Element; + let forwardButton: JSX.Element | undefined; const forwardableEvent = getForwardableEvent(mxEvent, cli); if (contentActionable && forwardableEvent) { forwardButton = ( @@ -442,7 +442,7 @@ export default class MessageContextMenu extends React.Component ); } - let pinButton: JSX.Element; + let pinButton: JSX.Element | undefined; if (contentActionable && this.state.canPin) { pinButton = ( /> ); - let unhidePreviewButton: JSX.Element; + let unhidePreviewButton: JSX.Element | undefined; if (eventTileOps?.isWidgetHidden()) { unhidePreviewButton = ( ); } - let permalinkButton: JSX.Element; + let permalinkButton: JSX.Element | undefined; if (permalink) { permalinkButton = ( ); } - let endPollButton: JSX.Element; + let endPollButton: JSX.Element | undefined; if (this.canEndPoll(mxEvent)) { endPollButton = ( ); } - let quoteButton: JSX.Element; + let quoteButton: JSX.Element | undefined; if (eventTileOps && canSendMessages) { // this event is rendered using TextualBody quoteButton = ( @@ -517,7 +517,7 @@ export default class MessageContextMenu extends React.Component } // Bridges can provide a 'external_url' to link back to the source. - let externalURLButton: JSX.Element; + let externalURLButton: JSX.Element | undefined; if ( typeof mxEvent.getContent().external_url === "string" && isUrlPermitted(mxEvent.getContent().external_url) @@ -540,7 +540,7 @@ export default class MessageContextMenu extends React.Component ); } - let collapseReplyChainButton: JSX.Element; + let collapseReplyChainButton: JSX.Element | undefined; if (collapseReplyChain) { collapseReplyChainButton = ( ); } - let jumpToRelatedEventButton: JSX.Element; + let jumpToRelatedEventButton: JSX.Element | undefined; const relatedEventId = mxEvent.getWireContent()?.["m.relates_to"]?.event_id; if (relatedEventId && SettingsStore.getValue("developerMode")) { jumpToRelatedEventButton = ( @@ -563,7 +563,7 @@ export default class MessageContextMenu extends React.Component ); } - let reportEventButton: JSX.Element; + let reportEventButton: JSX.Element | undefined; if (mxEvent.getSender() !== me) { reportEventButton = ( ); } - let copyLinkButton: JSX.Element; + let copyLinkButton: JSX.Element | undefined; if (link) { copyLinkButton = ( ); } - let copyButton: JSX.Element; + let copyButton: JSX.Element | undefined; if (rightClick && getSelectedText()) { copyButton = ( ); } - let editButton: JSX.Element; + let editButton: JSX.Element | undefined; if (rightClick && canEditContent(mxEvent)) { editButton = ( ); } - let replyButton: JSX.Element; + let replyButton: JSX.Element | undefined; if (rightClick && contentActionable && canSendMessages) { replyButton = ( ); } - let replyInThreadButton: JSX.Element; + let replyInThreadButton: JSX.Element | undefined; if ( rightClick && contentActionable && @@ -639,7 +639,7 @@ export default class MessageContextMenu extends React.Component replyInThreadButton = ; } - let reactButton; + let reactButton: JSX.Element | undefined; if (rightClick && contentActionable && canReact) { reactButton = ( ); } - let viewInRoomButton: JSX.Element; + let viewInRoomButton: JSX.Element | undefined; if (isThreadRootEvent) { viewInRoomButton = ( ); } - let nativeItemsList: JSX.Element; + let nativeItemsList: JSX.Element | undefined; if (copyButton || copyLinkButton) { nativeItemsList = ( @@ -672,7 +672,7 @@ export default class MessageContextMenu extends React.Component ); } - let quickItemsList: JSX.Element; + let quickItemsList: JSX.Element | undefined; if (editButton || replyButton || reactButton) { quickItemsList = ( @@ -703,12 +703,12 @@ export default class MessageContextMenu extends React.Component ); - let redactItemList: JSX.Element; + let redactItemList: JSX.Element | undefined; if (redactButton) { redactItemList = {redactButton}; } - let reactionPicker: JSX.Element; + let reactionPicker: JSX.Element | undefined; if (this.state.reactionPickerDisplayed) { const buttonRect = (this.reactButtonRef.current as HTMLElement)?.getBoundingClientRect(); reactionPicker = ( diff --git a/src/components/views/elements/AccessibleButton.tsx b/src/components/views/elements/AccessibleButton.tsx index 4bceab5ac91..10f18f1f31c 100644 --- a/src/components/views/elements/AccessibleButton.tsx +++ b/src/components/views/elements/AccessibleButton.tsx @@ -14,7 +14,7 @@ limitations under the License. */ -import React, { HTMLAttributes, InputHTMLAttributes, ReactHTML, ReactNode } from "react"; +import React, { HTMLAttributes, InputHTMLAttributes, ReactNode } from "react"; import classnames from "classnames"; import { getKeyBindingsManager } from "../../../KeyBindingsManager"; @@ -91,7 +91,7 @@ export interface IAccessibleButtonProps extends React.InputHTMLAttributes({ - element, + element = "div" as T, onClick, children, kind, @@ -169,7 +169,6 @@ export default function AccessibleButton( } AccessibleButton.defaultProps = { - element: "div" as keyof ReactHTML, role: "button", tabIndex: 0, }; diff --git a/src/components/views/elements/AppPermission.tsx b/src/components/views/elements/AppPermission.tsx index 3b1c18a692d..7adae9113b5 100644 --- a/src/components/views/elements/AppPermission.tsx +++ b/src/components/views/elements/AppPermission.tsx @@ -61,8 +61,6 @@ export default class AppPermission extends React.Component { // Set all this into the initial state this.state = { - widgetDomain: null, - isWrapped: null, roomMember, ...urlInfo, }; diff --git a/src/components/views/elements/DesktopCapturerSourcePicker.tsx b/src/components/views/elements/DesktopCapturerSourcePicker.tsx index cf8f6b018db..7be62a89998 100644 --- a/src/components/views/elements/DesktopCapturerSourcePicker.tsx +++ b/src/components/views/elements/DesktopCapturerSourcePicker.tsx @@ -33,7 +33,8 @@ export function getDesktopCapturerSources(): Promise([]); } export enum Tabs { diff --git a/src/components/views/elements/DialogButtons.tsx b/src/components/views/elements/DialogButtons.tsx index 39c943b405b..633e5381a0b 100644 --- a/src/components/views/elements/DialogButtons.tsx +++ b/src/components/views/elements/DialogButtons.tsx @@ -69,7 +69,7 @@ export default class DialogButtons extends React.Component { }; private onCancelClick = (event: React.MouseEvent): void => { - this.props.onCancel(event); + this.props.onCancel!(event); }; public render(): React.ReactNode { @@ -77,9 +77,9 @@ export default class DialogButtons extends React.Component { if (this.props.primaryButtonClass) { primaryButtonClassName += " " + this.props.primaryButtonClass; } - let cancelButton; - if (this.props.cancelButton || this.props.hasCancel) { + let cancelButton: JSX.Element | undefined; + if (this.props.cancelButton && this.props.hasCancel) { cancelButton = (