BFE.dev solution for TypeScript puzzle
5. implement Pick<T, K>
Looking at the description, MyPick<T, K>
should generate an object type which has property names listed in K, so we should use Mapped Type.
type MyPick<T, K> = {
[P in K]: T[P]
}
This doesn't work since TypeScript complaints about T[P]
unless P
is the property key of T
, we can add the type constraint on K.
type MyPick<T, K extends keyof T> = {
[P in K]: T[P]
}
You might also be able to find a solution fromcommunity posts or fromAI solution.