KeysOfUnion

Obtiene todas las claves de una unión de tipos objeto.

#types #typescript #utility-type
export type KeysOfUnion<T> = T extends T ? keyof T : never;
// Usage
type A = { a: string; shared: number };
type B = { b: boolean; shared: number };
type AllKeys = KeysOfUnion<A | B>;
// 'a' | 'b' | 'shared'

Comparte este snippet

Comentarios