type MyPick<T, K extends keyof T> = {
[key in K]: T[key];
}
Solution by seungjae0619 #37983
type MyPick<T, K extends keyof T> = {
[P in K]: T[P]
}
Solution by sohan9819 #37980
type MyPick<T, K extends keyof T> = {
[k in K]: T[k];
};
Solution by dubovea #37970
// 解答をここに記入
type MyPick<T, K extends keyof T> = {
[k in K] : T[k]
}
Solution by tac-tac-go #37902
type MyPick<T, K extends keyof T> = {
[P in K]: T[P]
}
Solution by LoveDreaMing #37900
/* _____________ Your Code Here _____________ */
type MyPick<T, K extends keyof T> = { [k in K]: T[k]}
/* _____________ 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
}
Solution by tuannvnguyen #37866
// your answers
type MyPick<T, K extends keyof T> = {
[P in K]: T[P]
}
Solution by istamal #37846
type MyPick<T, K extends keyof T> = {
[P in K]: T[P]
}
Solution by Hansol46 #37829
type MyPick<T, K extends keyof T> = {
[key in K]: T[key]
}
Solution by pkutsenko #37818
type myKick<T , K extends keyof T>={
[key in K]:T[key]
}
Solution by liuyee12 #37786
type MyPick<T, K extends keyof T> = {
[X in K]: T[X]
}
Solution by jisooooooooooo #37778
type MyPick<T, K extends keyof T> = {
[key in K]: T[key];
}
Solution by Tnalxmsk #37774
// your answers
type MyPick<T, K extends keyof T> = { [A in K]: T[A] }
Solution by theidentify #37770
// your answers
Solution by Brahima-Fofana #37756
type MyPick<T, K extends keyof T> = {
[key in K]: T[key]
}
Solution by JohnGlod #37750
type MyPick<T extends object, K extends keyof T> = { [key in K]: T[key] }
Solution by R00tx-0xf0rd #37749
type MyPick<T, K extends keyof T> = {
[p in K]: T[p]
}
Solution by GuoYingHAOG #37717
type MyPick<Type, Keys extends keyof Type> = {
[Key in Keys]: Type[Key]
}
Solution by gyugod93 #37714
type MyPick<T, K extends keyof T> = {
[k in K]: T[k]
}
Solution by jthw1005 #37709
type MyPick<T, K> = {
[Key in keyof T as Key extends K ? Key : never]: T[Key]
}
Solution by rauf322 #37699
type MyPick<ObjectType, SelectedKeys extends keyof ObjectType> = {
[Key in SelectedKeys]: ObjectType[Key]
}
Solution by ortima #37683
type MyPick<T, K extends keyof T> = {
[key in K]: T[key]
}
/* _____________ 测试用例 _____________ */
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
}
Solution by PosionEdgar #37675
type MyPick<T, K extends keyof T> = {
[P in K]: T[P]
}
Solution by Ju-MINJAE #37662
type MyPick<InputType extends object, Key extends keyof InputType> = {
[P in Key]: InputType[P];
};
Solution by AlexanderNP #37642
type MyPick<T, K extends keyof T> = {[P in K]: T[P]}
Solution by jjojae9393 #37595
type MyPick<T, K extends keyof T> = { [S in K]: T[S] }
Solution by tomo-local #37569
type MyPick<T, K extends keyof T> = { [P in K]: T[P] }
Solution by amirdaGankhuyag #37513
interface Todo { title: string description: string completed: boolean }
type MyPick<T, K extends keyof T> = { [P in K]: T[P] }
type TodoPreview = MyPick<Todo, 'title' | 'completed'>
const todo: TodoPreview = { title: 'Clean room', completed: false, }
Solution by amirdaGankhuyag #37512
// your answers
Solution by dzheey #37474