Tiny Wins Home

Union of all types in another type. Typescript

December 09, 2022

If you want the union type of all the types of the values in another type in typescript you can use the keyof operator.

type Thing = {
  foo: string;
  bar: boolean;

type ThingTypes = Thing[keyof Thing];
// string | boolean