Good morning,
I'm trying to achieve the following,
Create a type that will take the keys from the following object
const obj = {
setName: () => void;
setAge: () => void;
}
And generate a Tuple type using a mapped type that makes
[ “setName”, “setAge” ]
I might be completely wrong here but for the mapped type I think this would work
type MyType<T> = {
[P in keyof T]: T[P]
}
But if T is a type from the object I showcased above, I would end up with the following type
type MappedType = {
setName: () => void;
setAge: () => void;
}
But what I want is
type MappedType = [setName, setAge]
Any help is greatly appreciated.
what you need is
UnionToTuple<U>
:click here to try the code in ts playground