Type Challenges Judge

Pick

提出詳細

/* _____________ Your Code Here _____________ */ // Tのなかにある部分型Kを抜き出す // Tはなんでもいい // Kは部分型 // keyof Todo // それぞれのkeyのtypeは引き継ぐ // mapping // Kのunionからkeyを取りたい // in keyofでiterateする type MyPick<T, K extends T> = { [S in keyof K]: typeof (T[S]); } /* _____________ Test Cases _____________ */ import type { Equal, Expect } from '@type-challenges/utils' type cases = [ Expect<Equal<Expected1, MyPick<Todo, 'title'>>>, Expect<Equal<Expected2, MyPick<Todo, 'title' | 'completed'>>>, // @ts-expect-error MyPick<Todo, 'title' | 'completed' | 'invalid'>, ] interface Todo { title: string description: string completed: boolean } interface Expected1 { title: string } interface Expected2 { title: string completed: boolean }
提出日時2024-03-06 06:28:56
問題Pick
ユーザーratmie
ステータスJudging
テストケース
import type { Equal, Expect } from '@type-challenges/utils' type cases = [ Expect<Equal<Expected1, MyPick<Todo, 'title'>>>, Expect<Equal<Expected2, MyPick<Todo, 'title' | 'completed'>>>, // @ts-expect-error MyPick<Todo, 'title' | 'completed' | 'invalid'>, ] interface Todo { title: string description: string completed: boolean } interface Expected1 { title: string } interface Expected2 { title: string completed: boolean }