Skip to content

Instantly share code, notes, and snippets.

@so1ve
Created February 26, 2024 01:59
Show Gist options
  • Save so1ve/6e4d306ef8237f12bd34b0c2601b998d to your computer and use it in GitHub Desktop.
Save so1ve/6e4d306ef8237f12bd34b0c2601b998d to your computer and use it in GitHub Desktop.
chain (buggy)
const LastSymbol = Symbol();
type InitialLastType = typeof LastSymbol;
type GenerateChainArray<T extends any[], Last = InitialLastType> = T extends []
? []
: T extends [infer Head, ...infer Rest]
? [
Last extends InitialLastType ? () => Head : (arg: Last) => Head,
...GenerateChainArray<Rest, Head>,
]
: [];
declare function chain<T extends any[]>(fns: GenerateChainArray<T>): boolean;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment