1

I would like to have a type transformer which discards the keys of an interface and creates the union type of the value types of the interface. For instance here is an interface, Dog, and the extracted type DogProperties:

interface Dog {
  name: string
  birth: number
}

type DogProperties = ValueType<typeof dog> // DogProperties = string | number

How can I achieve the type transformer ValueType? I'm under the impression that it'll require using keyof, but I'm not sure how.

Mathieu CAROFF
  • 1,230
  • 13
  • 19

1 Answers1

1

The answer is actually simple:

export type ValueType<T> = T[keyof T]

I found it in the answers to Types from both keys and values of object in Typescript

Mathieu CAROFF
  • 1,230
  • 13
  • 19