Enable @typescript-eslint/explicit-function-return-type
in /src (#9788)
* Enable `@typescript-eslint/explicit-member-accessibility` on /src * Prettier * Enable `@typescript-eslint/explicit-function-return-type` in /src * Fix types * tsc strict fixes * Delint * Fix test * Fix bad merge
This commit is contained in:
parent
7a36ba0fde
commit
030b7e90bf
683 changed files with 3459 additions and 3013 deletions
|
@ -18,10 +18,14 @@ import { useEffect } from "react";
|
|||
|
||||
const DEBOUNCE_TIMEOUT = 100;
|
||||
|
||||
export function useDebouncedCallback<T extends any[]>(enabled: boolean, callback: (...params: T) => void, params: T) {
|
||||
export function useDebouncedCallback<T extends any[]>(
|
||||
enabled: boolean,
|
||||
callback: (...params: T) => void,
|
||||
params: T,
|
||||
): void {
|
||||
useEffect(() => {
|
||||
let handle: number | null = null;
|
||||
const doSearch = () => {
|
||||
const doSearch = (): void => {
|
||||
handle = null;
|
||||
callback(...params);
|
||||
};
|
||||
|
|
|
@ -21,10 +21,10 @@ import { Room, RoomEvent } from "matrix-js-sdk/src/models/room";
|
|||
|
||||
import { useTypedEventEmitter } from "./useEventEmitter";
|
||||
|
||||
const tryGetContent = <T extends {}>(ev?: MatrixEvent) => (ev ? ev.getContent<T>() : undefined);
|
||||
const tryGetContent = <T extends {}>(ev?: MatrixEvent): T => (ev ? ev.getContent<T>() : undefined);
|
||||
|
||||
// Hook to simplify listening to Matrix account data
|
||||
export const useAccountData = <T extends {}>(cli: MatrixClient, eventType: string) => {
|
||||
export const useAccountData = <T extends {}>(cli: MatrixClient, eventType: string): T => {
|
||||
const [value, setValue] = useState<T>(() => tryGetContent<T>(cli.getAccountData(eventType)));
|
||||
|
||||
const handler = useCallback(
|
||||
|
@ -40,7 +40,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) => {
|
||||
export const useRoomAccountData = <T extends {}>(room: Room, eventType: string): T => {
|
||||
const [value, setValue] = useState<T>(() => tryGetContent<T>(room.getAccountData(eventType)));
|
||||
|
||||
const handler = useCallback(
|
||||
|
|
|
@ -19,13 +19,13 @@ import { useCallback, useEffect, useRef } from "react";
|
|||
|
||||
import SettingsStore from "../settings/SettingsStore";
|
||||
|
||||
const debuglog = (...args: any[]) => {
|
||||
const debuglog = (...args: any[]): void => {
|
||||
if (SettingsStore.getValue("debug_animation")) {
|
||||
logger.log.call(console, "Animation debuglog:", ...args);
|
||||
}
|
||||
};
|
||||
|
||||
export function useAnimation(enabled: boolean, callback: (timestamp: DOMHighResTimeStamp) => boolean) {
|
||||
export function useAnimation(enabled: boolean, callback: (timestamp: DOMHighResTimeStamp) => boolean): void {
|
||||
const handle = useRef<number | null>(null);
|
||||
|
||||
const handler = useCallback(
|
||||
|
|
|
@ -25,7 +25,14 @@ interface State {
|
|||
device: MediaDeviceInfo | null;
|
||||
}
|
||||
|
||||
export const useAudioDeviceSelection = (onDeviceChanged?: (device: MediaDeviceInfo) => void) => {
|
||||
export const useAudioDeviceSelection = (
|
||||
onDeviceChanged?: (device: MediaDeviceInfo) => void,
|
||||
): {
|
||||
currentDevice: MediaDeviceInfo;
|
||||
currentDeviceLabel: string;
|
||||
devices: MediaDeviceInfo[];
|
||||
setDevice(device: MediaDeviceInfo): void;
|
||||
} => {
|
||||
const shouldRequestPermissionsRef = useRef<boolean>(true);
|
||||
const [state, setState] = useState<State>({
|
||||
devices: [],
|
||||
|
@ -52,7 +59,7 @@ export const useAudioDeviceSelection = (onDeviceChanged?: (device: MediaDeviceIn
|
|||
});
|
||||
}
|
||||
|
||||
const setDevice = (device: MediaDeviceInfo) => {
|
||||
const setDevice = (device: MediaDeviceInfo): void => {
|
||||
const shouldNotify = device.deviceId !== state.device?.deviceId;
|
||||
MediaDeviceHandler.instance.setDevice(device.deviceId, MediaDeviceKindEnum.AudioInput);
|
||||
|
||||
|
|
|
@ -20,7 +20,10 @@ import { Dispatcher } from "flux";
|
|||
import { ActionPayload } from "../dispatcher/payloads";
|
||||
|
||||
// Hook to simplify listening to flux dispatches
|
||||
export const useDispatcher = (dispatcher: Dispatcher<ActionPayload>, handler: (payload: ActionPayload) => void) => {
|
||||
export const useDispatcher = (
|
||||
dispatcher: Dispatcher<ActionPayload>,
|
||||
handler: (payload: ActionPayload) => void,
|
||||
): void => {
|
||||
// Create a ref that stores handler
|
||||
const savedHandler = useRef((payload: ActionPayload) => {});
|
||||
|
||||
|
|
|
@ -47,7 +47,7 @@ export function useEventEmitter(emitter: EventEmitter | undefined, eventName: st
|
|||
if (!emitter) return;
|
||||
|
||||
// Create event listener that calls handler function stored in ref
|
||||
const eventListener = (...args) => savedHandler.current(...args);
|
||||
const eventListener = (...args): void => savedHandler.current(...args);
|
||||
|
||||
// Add event listener
|
||||
emitter.on(eventName, eventListener);
|
||||
|
|
|
@ -18,13 +18,16 @@ import { useState } from "react";
|
|||
|
||||
const favouriteMessageIds = JSON.parse(localStorage?.getItem("io_element_favouriteMessages") ?? "[]") as string[];
|
||||
|
||||
export default function useFavouriteMessages() {
|
||||
export default function useFavouriteMessages(): {
|
||||
toggleFavourite: (eventId: string) => void;
|
||||
isFavourite: (eventId: string) => boolean;
|
||||
} {
|
||||
const [, setX] = useState<string[]>();
|
||||
|
||||
//checks if an id already exist
|
||||
const isFavourite = (eventId: string): boolean => favouriteMessageIds.includes(eventId);
|
||||
|
||||
const toggleFavourite = (eventId: string) => {
|
||||
const toggleFavourite = (eventId: string): void => {
|
||||
isFavourite(eventId)
|
||||
? favouriteMessageIds.splice(favouriteMessageIds.indexOf(eventId), 1)
|
||||
: favouriteMessageIds.push(eventId);
|
||||
|
|
|
@ -22,7 +22,7 @@ export const useLocalEcho = <T>(
|
|||
errorFn: (error: Error) => void,
|
||||
): [value: T, handler: (value: T) => void] => {
|
||||
const [value, setValue] = useState(currentFactory);
|
||||
const handler = async (value: T) => {
|
||||
const handler = async (value: T): Promise<void> => {
|
||||
setValue(value);
|
||||
try {
|
||||
await setterFn(value);
|
||||
|
|
|
@ -29,7 +29,12 @@ export interface IProfileInfo {
|
|||
display_name?: string;
|
||||
}
|
||||
|
||||
export const useProfileInfo = () => {
|
||||
export const useProfileInfo = (): {
|
||||
ready: boolean;
|
||||
loading: boolean;
|
||||
profile: IProfileInfo | null;
|
||||
search(opts: IProfileInfoOpts): Promise<boolean>;
|
||||
} => {
|
||||
const [profile, setProfile] = useState<IProfileInfo | null>(null);
|
||||
|
||||
const [loading, setLoading] = useState(false);
|
||||
|
|
|
@ -38,7 +38,15 @@ export interface IPublicRoomsOpts {
|
|||
|
||||
let thirdParty: Protocols;
|
||||
|
||||
export const usePublicRoomDirectory = () => {
|
||||
export const usePublicRoomDirectory = (): {
|
||||
ready: boolean;
|
||||
loading: boolean;
|
||||
publicRooms: IPublicRoomsChunkRoom[];
|
||||
protocols: Protocols | null;
|
||||
config?: IPublicRoomDirectoryConfig | null;
|
||||
setConfig(config: IPublicRoomDirectoryConfig): void;
|
||||
search(opts: IPublicRoomsOpts): Promise<boolean>;
|
||||
} => {
|
||||
const [publicRooms, setPublicRooms] = useState<IPublicRoomsChunkRoom[]>([]);
|
||||
|
||||
const [config, setConfigInternal] = useState<IPublicRoomDirectoryConfig | null | undefined>(undefined);
|
||||
|
@ -50,7 +58,7 @@ export const usePublicRoomDirectory = () => {
|
|||
|
||||
const [updateQuery, updateResult] = useLatestResult<IRoomDirectoryOptions, IPublicRoomsChunkRoom[]>(setPublicRooms);
|
||||
|
||||
async function initProtocols() {
|
||||
async function initProtocols(): Promise<void> {
|
||||
if (!MatrixClientPeg.get()) {
|
||||
// We may not have a client yet when invoked from welcome page
|
||||
setReady(true);
|
||||
|
@ -63,7 +71,7 @@ export const usePublicRoomDirectory = () => {
|
|||
}
|
||||
}
|
||||
|
||||
function setConfig(config: IPublicRoomDirectoryConfig) {
|
||||
function setConfig(config: IPublicRoomDirectoryConfig): void {
|
||||
if (!ready) {
|
||||
throw new Error("public room configuration not initialised yet");
|
||||
} else {
|
||||
|
|
|
@ -19,7 +19,7 @@ import { useEffect, useState } from "react";
|
|||
import SettingsStore from "../settings/SettingsStore";
|
||||
|
||||
// Hook to fetch the value of a setting and dynamically update when it changes
|
||||
export const useSettingValue = <T>(settingName: string, roomId: string = null, excludeDefault = false) => {
|
||||
export const useSettingValue = <T>(settingName: string, roomId: string = null, excludeDefault = false): T => {
|
||||
const [value, setValue] = useState(SettingsStore.getValue<T>(settingName, roomId, excludeDefault));
|
||||
|
||||
useEffect(() => {
|
||||
|
|
|
@ -26,7 +26,11 @@ export interface SlidingSyncRoomSearchOpts {
|
|||
query?: string;
|
||||
}
|
||||
|
||||
export const useSlidingSyncRoomSearch = () => {
|
||||
export const useSlidingSyncRoomSearch = (): {
|
||||
loading: boolean;
|
||||
rooms: Room[];
|
||||
search(opts: SlidingSyncRoomSearchOpts): Promise<boolean>;
|
||||
} => {
|
||||
const [rooms, setRooms] = useState<Room[]>([]);
|
||||
|
||||
const [loading, setLoading] = useState(false);
|
||||
|
|
|
@ -20,7 +20,7 @@ import { useCallback, useEffect, useRef, useState } from "react";
|
|||
import SettingsStore from "../settings/SettingsStore";
|
||||
import { useAnimation } from "./useAnimation";
|
||||
|
||||
const debuglog = (...args: any[]) => {
|
||||
const debuglog = (...args: any[]): void => {
|
||||
if (SettingsStore.getValue("debug_animation")) {
|
||||
logger.log.call(console, "Animation debuglog:", ...args);
|
||||
}
|
||||
|
|
|
@ -36,7 +36,7 @@ export const useSpaceResults = (space?: Room, query?: string): [IHierarchyRoom[]
|
|||
|
||||
let unmounted = false;
|
||||
|
||||
(async () => {
|
||||
(async (): Promise<void> => {
|
||||
while (hierarchy?.canLoadMore && !unmounted && space === hierarchy.root) {
|
||||
await hierarchy.load();
|
||||
if (hierarchy.canLoadMore) hierarchy.load(); // start next load so that the loading attribute is right
|
||||
|
|
|
@ -20,7 +20,7 @@ import { Dispatch, SetStateAction, useState } from "react";
|
|||
// Returns value and method to change the state value
|
||||
export const useStateCallback = <T>(initialValue: T, callback: (v: T) => void): [T, Dispatch<SetStateAction<T>>] => {
|
||||
const [value, setValue] = useState(initialValue);
|
||||
const interceptSetValue = (newVal: T) => {
|
||||
const interceptSetValue = (newVal: T): void => {
|
||||
setValue(newVal);
|
||||
callback(newVal);
|
||||
};
|
||||
|
|
|
@ -20,7 +20,7 @@ import { Dispatch, SetStateAction, useState } from "react";
|
|||
// Returns value, method to toggle boolean value and method to set the boolean value
|
||||
export const useStateToggle = (initialValue = false): [boolean, () => void, Dispatch<SetStateAction<boolean>>] => {
|
||||
const [value, setValue] = useState(initialValue);
|
||||
const toggleValue = () => {
|
||||
const toggleValue = (): void => {
|
||||
setValue(!value);
|
||||
};
|
||||
return [value, toggleValue, setValue];
|
||||
|
|
|
@ -19,7 +19,7 @@ import { useEffect, useRef, useState } from "react";
|
|||
type Handler = () => void;
|
||||
|
||||
// Hook to simplify timeouts in functional components
|
||||
export const useTimeout = (handler: Handler, timeoutMs: number) => {
|
||||
export const useTimeout = (handler: Handler, timeoutMs: number): void => {
|
||||
// Create a ref that stores handler
|
||||
const savedHandler = useRef<Handler>();
|
||||
|
||||
|
@ -38,7 +38,7 @@ export const useTimeout = (handler: Handler, timeoutMs: number) => {
|
|||
};
|
||||
|
||||
// Hook to simplify intervals in functional components
|
||||
export const useInterval = (handler: Handler, intervalMs: number) => {
|
||||
export const useInterval = (handler: Handler, intervalMs: number): void => {
|
||||
// Create a ref that stores handler
|
||||
const savedHandler = useRef<Handler>();
|
||||
|
||||
|
@ -57,7 +57,7 @@ export const useInterval = (handler: Handler, intervalMs: number) => {
|
|||
};
|
||||
|
||||
// Hook to simplify a variable counting down to 0, handler called when it reached 0
|
||||
export const useExpiringCounter = (handler: Handler, intervalMs: number, initialCount: number) => {
|
||||
export const useExpiringCounter = (handler: Handler, intervalMs: number, initialCount: number): number => {
|
||||
const [count, setCount] = useState(initialCount);
|
||||
useInterval(() => setCount((c) => c - 1), intervalMs);
|
||||
if (count === 0) {
|
||||
|
|
|
@ -22,11 +22,17 @@ import { useEffect, useRef, useState } from "react";
|
|||
* @param {boolean} defaultValue Default value
|
||||
* @param {number} timeoutMs Time after that the value will be reset
|
||||
*/
|
||||
export const useTimeoutToggle = (defaultValue: boolean, timeoutMs: number) => {
|
||||
export const useTimeoutToggle = (
|
||||
defaultValue: boolean,
|
||||
timeoutMs: number,
|
||||
): {
|
||||
value: boolean;
|
||||
toggle(): void;
|
||||
} => {
|
||||
const timeoutId = useRef<number | undefined>();
|
||||
const [value, setValue] = useState<boolean>(defaultValue);
|
||||
|
||||
const toggle = () => {
|
||||
const toggle = (): void => {
|
||||
setValue(!defaultValue);
|
||||
timeoutId.current = window.setTimeout(() => setValue(defaultValue), timeoutMs);
|
||||
};
|
||||
|
|
|
@ -25,7 +25,12 @@ export interface IUserDirectoryOpts {
|
|||
query?: string;
|
||||
}
|
||||
|
||||
export const useUserDirectory = () => {
|
||||
export const useUserDirectory = (): {
|
||||
ready: boolean;
|
||||
loading: boolean;
|
||||
users: DirectoryMember[];
|
||||
search(opts: IUserDirectoryOpts): Promise<boolean>;
|
||||
} => {
|
||||
const [users, setUsers] = useState<DirectoryMember[]>([]);
|
||||
|
||||
const [loading, setLoading] = useState(false);
|
||||
|
|
|
@ -58,7 +58,7 @@ function useUserOnboardingContextValue<T>(defaultValue: T, callback: (cli: Matri
|
|||
|
||||
let handle: number | null = null;
|
||||
let enabled = true;
|
||||
const repeater = async () => {
|
||||
const repeater = async (): Promise<void> => {
|
||||
if (handle !== null) {
|
||||
clearTimeout(handle);
|
||||
handle = null;
|
||||
|
|
|
@ -48,7 +48,7 @@ export interface UserOnboardingTaskWithResolvedCompletion extends Omit<UserOnboa
|
|||
completed: boolean;
|
||||
}
|
||||
|
||||
const onClickStartDm = (ev: ButtonEvent) => {
|
||||
const onClickStartDm = (ev: ButtonEvent): void => {
|
||||
PosthogTrackers.trackInteraction("WebUserOnboardingTaskSendDm", ev);
|
||||
defaultDispatcher.dispatch({ action: "view_create_chat" });
|
||||
};
|
||||
|
@ -144,7 +144,7 @@ const tasks: UserOnboardingTask[] = [
|
|||
},
|
||||
];
|
||||
|
||||
export function useUserOnboardingTasks(context: UserOnboardingContext) {
|
||||
export function useUserOnboardingTasks(context: UserOnboardingContext): UserOnboardingTaskWithResolvedCompletion[] {
|
||||
const useCase = useSettingValue<UseCase | null>("FTUE.useCaseSelection") ?? UseCase.Skip;
|
||||
|
||||
return useMemo<UserOnboardingTaskWithResolvedCompletion[]>(() => {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue