TypeScript
Table of Contents
1. Type-level programming
// https://github.com/microsoft/TypeScript/issues/23182#issuecomment-583330532 type NeverAlternative<T, P, N> = [T] extends [never] ? P : N; type Union<T, U> = NeverAlternative<T, U, T | U>; class C<T = never> { frob<U>(obj: Record<keyof U, any>): C<Union<T, keyof U>> { return new C<Union<T, keyof U>>(); } get(key: T) { } } // x : C<never> const x = new C(); // y : C<'a' | 'b'> const y = x.frob({ 'a': 1, 'b': 2 }); y.get('a'); // z : C<'a' | 'b' | 'bleh'> const z = y.frob({ bleh: 32 })
2. Backlinks
- Related notes (cheatsheet.org)