TypeScript Parameters - ChoDragon9/posts GitHub Wiki
함수 인자 추론.
type Action = (num: number) => void;
function userRequest<Func extends (...args: any[]) => any>(action: Func) {
const request: (...param: Parameters<Func>) => void = (...param) => {
}
return request;
}
declare const action: Action;
const req = userRequest(action);
req("1");
req(1);
const DEBOUNCE_TIME_MS = 100;
type Callback = (...param: unknown[]) => unknown;
export default <Func extends Callback> (callback: Func, debounceTimeMs = DEBOUNCE_TIME_MS) => {
let timer;
return (...args: Parameters<Func>) => {
clearTimeout(timer);
timer = setTimeout(() => {
callback(...args);
}, debounceTimeMs);
};
};