Better types

This commit is contained in:
Jake Archibald
2021-02-05 14:36:36 +00:00
parent 73ac08c0cd
commit 1c1e4c7c01

View File

@@ -387,8 +387,9 @@ export function abortable<T>(
return abortableFunc(signal, () => promise); return abortableFunc(signal, () => promise);
} }
type SetAbortArg = (() => void) | undefined;
type AbortableCallback<T> = ( type AbortableCallback<T> = (
setAbort: (abortCallback: () => void) => void, setAbort: (abortCallback: SetAbortArg) => void,
) => Promise<T>; ) => Promise<T>;
/** /**
@@ -402,9 +403,9 @@ export async function abortableFunc<T>(
callback: AbortableCallback<T>, callback: AbortableCallback<T>,
): Promise<T> { ): Promise<T> {
if (signal) assertSignal(signal); if (signal) assertSignal(signal);
let onAbort: () => void; let onAbort: (() => void) | undefined;
let listener: () => void; let listener: () => void;
const setOnAbort = (abortCallback: () => void) => { const setOnAbort = (abortCallback: SetAbortArg) => {
onAbort = abortCallback; onAbort = abortCallback;
}; };
const promise = callback(setOnAbort); const promise = callback(setOnAbort);