refactor(editor): Fix type errors in ResourcesListLayout.vue (no-changelog) (#9461)

This commit is contained in:
Ricardo Espinoza
2024-05-20 09:01:38 -04:00
committed by GitHub
parent 87f965e905
commit 75919397d6
2 changed files with 226 additions and 159 deletions

View File

@@ -6,13 +6,16 @@ export interface DebounceOptions {
trailing?: boolean;
}
export type DebouncedFunction<R = void> = (...args: unknown[]) => R;
export type DebouncedFunction<Args extends unknown[] = unknown[], R = void> = (...args: Args) => R;
export function useDebounce() {
// Create a ref for the WeakMap to store debounced functions.
const debounceCache = ref(new WeakMap<DebouncedFunction<unknown>, DebouncedFunction<unknown>>());
const debounceCache = ref(
// eslint-disable-next-line @typescript-eslint/no-explicit-any
new WeakMap<DebouncedFunction<any, any>, DebouncedFunction<any, any>>(),
);
const debounce = <T extends DebouncedFunction<ReturnType<T>>>(
const debounce = <T extends DebouncedFunction<Parameters<T>, ReturnType<T>>>(
fn: T,
options: DebounceOptions,
): T => {
@@ -24,7 +27,7 @@ export function useDebounce() {
// If a debounced version is not found, create one and store it in the WeakMap.
if (debouncedFn === undefined) {
debouncedFn = _debounce(
async (...args: unknown[]) => {
async (...args: Parameters<T>) => {
return fn(...args);
},
debounceTime,
@@ -37,7 +40,7 @@ export function useDebounce() {
return debouncedFn as T;
};
const callDebounced = <T extends DebouncedFunction<ReturnType<T>>>(
const callDebounced = <T extends DebouncedFunction<Parameters<T>, ReturnType<T>>>(
fn: T,
options: DebounceOptions,
...inputParameters: Parameters<T>