type-challenges
type-challenges copied to clipboard
4 - Pick
✍️ Answers
Name your title starting with the question no you are trying to answer.
For example:
#12 - my one-line solution
type MyPick<T, K extends keyof T> = { [S in K]: T[S] }
In typescrip 4.7.4 this is not work.
type MyPick<T, K extends keyof T> = { [S in K]: T[S] }
interface Todo {
title: string
description: string
completed: boolean
}
/*
type test = {
title: string;
completed: boolean;
invalid: unknown;
}
*/
type test = MyPick<Todo, 'title' | 'completed' | 'invalid'>
type MyPick<T extends object, K extends keyof T> = { [key in K]: T[key] }