Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
ObjectBuilder.ts
type NumericIndex = '0' | '1' | '2' | '3' | '4' | '5' | '6' | '7' | '8' | '9'
type Index<T extends any[]> = NumericIndex & keyof T
type UnionToIntersection<U> =
(U extends any ? (k: U)=>void : never) extends ((k: infer I)=>void) ? I : never
type Builder<State = {}> = {
(): State
<A extends string[]>(...namedArgsOrder: A): <
V extends { [K in keyof A]: any },
T = UnionToIntersection<{ [K in Index<A>]: Record<string & A[K], V[K]> }[Index<A>]>
>(..._: V) => Omit<State, keyof T> & T
<T extends {}>(_: T): Builder<Omit<State, keyof T> & T>
}
declare const a: Builder
const test = a('where', 'what')
test('sdgsfhg', 1)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment