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

0

1 Answer 1

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.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.