Conform more of the code base to strict null checking (#10147)
* Conform more of the code base to strict null checking * More strict fixes * More strict work * Fix missing optional type * Iterate
This commit is contained in:
parent
fa036a5080
commit
da7aa4055e
380 changed files with 682 additions and 694 deletions
|
@ -26,11 +26,11 @@ import { Optional } from "matrix-events-sdk";
|
|||
import { useTypedEventEmitter } from "../useEventEmitter";
|
||||
|
||||
export const getTopic = (room: Room): Optional<TopicState> => {
|
||||
const content: MRoomTopicEventContent = room?.currentState?.getStateEvents(EventType.RoomTopic, "")?.getContent();
|
||||
const content = room?.currentState?.getStateEvents(EventType.RoomTopic, "")?.getContent<MRoomTopicEventContent>();
|
||||
return !!content ? parseTopicContent(content) : null;
|
||||
};
|
||||
|
||||
export function useTopic(room: Room): TopicState {
|
||||
export function useTopic(room: Room): Optional<TopicState> {
|
||||
const [topic, setTopic] = useState(getTopic(room));
|
||||
useTypedEventEmitter(room.currentState, RoomStateEvent.Events, (ev: MatrixEvent) => {
|
||||
if (ev.getType() !== EventType.RoomTopic) return;
|
||||
|
|
|
@ -25,7 +25,7 @@ export const useRecentSearches = (): [Room[], () => void] => {
|
|||
const [rooms, setRooms] = useState(() => {
|
||||
const cli = MatrixClientPeg.get();
|
||||
const recents = SettingsStore.getValue<string[]>("SpotlightSearch.recentSearches", null);
|
||||
return recents.map((r) => cli.getRoom(r)).filter(Boolean);
|
||||
return recents.map((r) => cli.getRoom(r)).filter(Boolean) as Room[];
|
||||
});
|
||||
|
||||
return [
|
||||
|
|
|
@ -21,11 +21,11 @@ import { Room, RoomEvent } from "matrix-js-sdk/src/models/room";
|
|||
|
||||
import { useTypedEventEmitter } from "./useEventEmitter";
|
||||
|
||||
const tryGetContent = <T extends {}>(ev?: MatrixEvent): T => (ev ? ev.getContent<T>() : undefined);
|
||||
const tryGetContent = <T extends {}>(ev?: MatrixEvent): T | undefined => ev?.getContent<T>();
|
||||
|
||||
// Hook to simplify listening to Matrix account data
|
||||
export const useAccountData = <T extends {}>(cli: MatrixClient, eventType: string): T => {
|
||||
const [value, setValue] = useState<T>(() => tryGetContent<T>(cli.getAccountData(eventType)));
|
||||
const [value, setValue] = useState<T | undefined>(() => tryGetContent<T>(cli.getAccountData(eventType)));
|
||||
|
||||
const handler = useCallback(
|
||||
(event) => {
|
||||
|
@ -41,7 +41,7 @@ export const useAccountData = <T extends {}>(cli: MatrixClient, eventType: strin
|
|||
|
||||
// Hook to simplify listening to Matrix room account data
|
||||
export const useRoomAccountData = <T extends {}>(room: Room, eventType: string): T => {
|
||||
const [value, setValue] = useState<T>(() => tryGetContent<T>(room.getAccountData(eventType)));
|
||||
const [value, setValue] = useState<T | undefined>(() => tryGetContent<T>(room.getAccountData(eventType)));
|
||||
|
||||
const handler = useCallback(
|
||||
(event) => {
|
||||
|
|
|
@ -18,8 +18,8 @@ import { useState, useEffect, DependencyList } from "react";
|
|||
|
||||
type Fn<T> = () => Promise<T>;
|
||||
|
||||
export const useAsyncMemo = <T>(fn: Fn<T>, deps: DependencyList, initialValue?: T): T => {
|
||||
const [value, setValue] = useState<T>(initialValue);
|
||||
export const useAsyncMemo = <T>(fn: Fn<T>, deps: DependencyList, initialValue?: T): T | undefined => {
|
||||
const [value, setValue] = useState<T | undefined>(initialValue);
|
||||
useEffect(() => {
|
||||
let discard = false;
|
||||
fn().then((v) => {
|
||||
|
|
|
@ -28,7 +28,7 @@ interface State {
|
|||
export const useAudioDeviceSelection = (
|
||||
onDeviceChanged?: (device: MediaDeviceInfo) => void,
|
||||
): {
|
||||
currentDevice: MediaDeviceInfo;
|
||||
currentDevice: MediaDeviceInfo | null;
|
||||
currentDeviceLabel: string;
|
||||
devices: MediaDeviceInfo[];
|
||||
setDevice(device: MediaDeviceInfo): void;
|
||||
|
|
|
@ -22,7 +22,7 @@ import type { EventEmitter } from "events";
|
|||
type Handler = (...args: any[]) => void;
|
||||
|
||||
export function useTypedEventEmitter<Events extends string, Arguments extends ListenerMap<Events>>(
|
||||
emitter: TypedEventEmitter<Events, Arguments>,
|
||||
emitter: TypedEventEmitter<Events, Arguments> | undefined,
|
||||
eventName: Events,
|
||||
handler: Handler,
|
||||
): void {
|
||||
|
|
|
@ -17,7 +17,7 @@ limitations under the License.
|
|||
import { useState } from "react";
|
||||
|
||||
export default function useHover(
|
||||
ignoreHover?: (ev: React.MouseEvent) => boolean,
|
||||
ignoreHover: (ev: React.MouseEvent) => boolean,
|
||||
): [boolean, { onMouseOver: () => void; onMouseLeave: () => void; onMouseMove: (ev: React.MouseEvent) => void }] {
|
||||
const [hovered, setHoverState] = useState(false);
|
||||
|
||||
|
|
|
@ -39,7 +39,7 @@ export const useProfileInfo = (): {
|
|||
|
||||
const [loading, setLoading] = useState(false);
|
||||
|
||||
const [updateQuery, updateResult] = useLatestResult<string, IProfileInfo | null>(setProfile);
|
||||
const [updateQuery, updateResult] = useLatestResult<string | undefined, IProfileInfo | null>(setProfile);
|
||||
|
||||
const search = useCallback(
|
||||
async ({ query: term }: IProfileInfoOpts): Promise<boolean> => {
|
||||
|
|
|
@ -28,8 +28,8 @@ const defaultMapper: Mapper<RoomState> = (roomState: RoomState) => roomState;
|
|||
export const useRoomState = <T extends any = RoomState>(
|
||||
room?: Room,
|
||||
mapper: Mapper<T> = defaultMapper as Mapper<T>,
|
||||
): T => {
|
||||
const [value, setValue] = useState<T>(room ? mapper(room.currentState) : undefined);
|
||||
): T | undefined => {
|
||||
const [value, setValue] = useState<T | undefined>(room ? mapper(room.currentState) : undefined);
|
||||
|
||||
const update = useCallback(() => {
|
||||
if (!room) return;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue