diff options
| author | Akshay Nair <phenax5@gmail.com> | 2023-01-09 19:08:10 +0530 |
|---|---|---|
| committer | Akshay Nair <phenax5@gmail.com> | 2023-01-09 19:08:10 +0530 |
| commit | 592f866637bfb8ef8a4a5c31e0984abf6df82532 (patch) | |
| tree | cfe4d0e7c6ce24ac9d6e73f782104f27db9cdaf8 /stdlib | |
| parent | efdcf6119e5de99a837189a06a2a23a088432f2d (diff) | |
| download | ts-types-lang-592f866637bfb8ef8a4a5c31e0984abf6df82532.tar.gz ts-types-lang-592f866637bfb8ef8a4a5c31e0984abf6df82532.zip | |
feat: adds some utility types
Diffstat (limited to '')
| -rw-r--r-- | stdlib/util.ts | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/stdlib/util.ts b/stdlib/util.ts new file mode 100644 index 0000000..832b0cb --- /dev/null +++ b/stdlib/util.ts @@ -0,0 +1,22 @@ +import { Kind1 } from './io' + +export type Let<f extends (...args: any) => any> = ReturnType<f> + +export type Apply<K extends Kind1, Val> = (K & { input: Val })['return'] + +export interface Id extends Kind1 { + return: this['input'] +} + +type ADTTT = { _type: string; value: any } + +interface ADTConstructor<A extends ADTTT> extends Kind1<A['value']> { + return: this['input'] extends infer Inp ? A & { value: Inp } : A +} + +type Pat = Record<string, ADTTT> +export type ADT<D extends Record<string, any>> = { + [k in keyof D]: { _type: k; value: D[k] } +} extends infer Rec extends Pat + ? Rec[keyof Rec] & { [k in keyof Rec]: ADTConstructor<Rec[k]> } + : never |
