From 8d261b2402f76a0700fb798318073a657b1de8b9 Mon Sep 17 00:00:00 2001 From: uri Date: Wed, 8 Jan 2025 11:24:20 +0200 Subject: [PATCH] missing-file --- src/composeTyping.ts | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 src/composeTyping.ts diff --git a/src/composeTyping.ts b/src/composeTyping.ts new file mode 100644 index 0000000..09d80ae --- /dev/null +++ b/src/composeTyping.ts @@ -0,0 +1,27 @@ +import { Func } from "./typing.ts"; + +type Identity = (x: T) => T; + +type UnwrapPromise = T extends Promise ? U : T; + +type UnwrapPromiseFn = ( + ...args: Parameters +) => UnwrapPromise>; + +type SimpleCompose = G extends (...args: infer GArgs) => infer GReturn + ? F extends (x: UnwrapPromise) => infer FReturn + ? (...args: GArgs) => UnwrapPromise + : never + : never; + +type Compose = F extends Identity + ? G extends Identity ? UnwrapPromiseFn : SimpleCompose + : SimpleCompose; + +export type ComposeMany = Fs extends [] ? never + : Fs extends [infer F extends Func] ? F + : Fs extends + [infer F extends Func, infer G extends Func, ...infer rest extends Func[]] + ? rest extends [] ? Compose + : Compose, Compose> + : never;