0

I am trying to convert the property types of any type T to a tuple containing the types of T in order.

type A = {
  a: string
  b: number
  c: string
}

type ToArray<T> = [...{[K in keyof T]: T[K]}[keyof T]] // doesn't work...

type ExpectedResult = [string, number, string]

I tried using the spread operator but couldn't get it to work.

Sandbox

Tobias S.
  • 21,159
  • 4
  • 27
  • 45

1 Answers1

1

This has already been covered in the following answer. Please be warned that doing this is not the best idea, and the reasons why are listed in this answer.

Taking it back to your use-case, you would use the code from the first answer as follows:

type A = {
  a: string
  b: number
  c: string
}

type ExpectedResult = ObjValueTuple<A>

Playground link.

Ovidijus Parsiunas
  • 2,512
  • 2
  • 8
  • 18