From 592f866637bfb8ef8a4a5c31e0984abf6df82532 Mon Sep 17 00:00:00 2001 From: Akshay Nair Date: Mon, 9 Jan 2023 19:08:10 +0530 Subject: feat: adds some utility types --- stdlib/util.ts | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 stdlib/util.ts (limited to 'stdlib/util.ts') 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 any> = ReturnType + +export type Apply = (K & { input: Val })['return'] + +export interface Id extends Kind1 { + return: this['input'] +} + +type ADTTT = { _type: string; value: any } + +interface ADTConstructor extends Kind1 { + return: this['input'] extends infer Inp ? A & { value: Inp } : A +} + +type Pat = Record +export type ADT> = { + [k in keyof D]: { _type: k; value: D[k] } +} extends infer Rec extends Pat + ? Rec[keyof Rec] & { [k in keyof Rec]: ADTConstructor } + : never -- cgit v1.3.1