Reputation: 961
Let's say I have this:
type CoolTuple = [string, number, boolean]
And, I want to map that type using some generic:
type CoolGeneric<T extends any[]> = ...
Such that:
CoolGeneric<CoolType> is [Wrapper<string>, Wrapper<number>, Wrapper<boolean>]
What would I do?
Upvotes: 0
Views: 623
Reputation: 187312
You want a mapped type:
type CoolGeneric<T extends any[]> = { [K in keyof T]: Wrapper<T[K]> }
Basically, for each key (indices of a tuple are keys), declare the type to be something that uses the property type T[K]
.
Upvotes: 2