UNPKG

trampoline-ts

Version:

A type-safe way to emulate tail-call optimization with trampolines

12 lines (11 loc) 467 B
export declare const THUNK_SYMBOL: unique symbol; export interface Thunk<T> extends Function { __THUNK__: typeof THUNK_SYMBOL; (): T; } export declare type ThunkOrValue<T> = T | Thunk<T>; export declare type UnwrapThunkDeep<T> = { 0: T extends Thunk<infer U> ? UnwrapThunkDeep<U> : T; }[T extends ThunkOrValue<T> ? 0 : never]; export declare const isThunk: <T>(value: any) => value is Thunk<T>; export declare const toThunk: <R>(fn: () => R) => Thunk<R>;