// your answers
type MyPick<T, K extends keyof T> = {
[Key in K]: T[Key];
}
Solution by AlexBraunMagic #36921
type MyPick<T extends Record<any,any>, K extends keyof T> = {
[key in K]: T[key]
}
Solution by tobi-ademola #36883
type MyPick<T, K extends keyof T> = { [P in K]: T[P]}
Solution by shaishabcoding #36837
type MyPick<T, K extends keyof T> = {
[P in K]: T[P]
} //Here we need change from any to this, because we create a new type containing only those fields from T that are specified in K, preserving their types.
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 GormanProg123 #36812
type MyPick<T, K extends keyof T> = {
[Key in K]: T[Key];
}
Solution by BernTheSeal #36807
type MyPick<T, K extends keyof T> = {
[P in K]: T[P]
}
/* _____________ 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 AnastasiaSv #36758
type MyPick<T, K extends keyof T> = {
[P ]: T[P]
};
Solution by seroak #36739
type MyPick<T, K extends keyof T> = {
[P in K]: T[P]
};
Solution by seroak #36738
// your answers
```type MyPick<T, K extends keyof T> = {
[P in K]: T[P];
};
Solution by VitaliyTheKeyboardist #36687
// your answers
type MyPick<T, K extends keyof T> = {
[key in K]: T[key]
}
Solution by desertby #36639
type MyPick<T, Y extends keyof T> = Omit<T, keyof Omit<T, Y>>
Solution by grishbar #36634
type MyPick <T, K extends keyof T> = {
[P in K]: T[P]
}
Solution by kimdaeyeobbb #36618
// 여기 풀이를 입력하세요
type MyPick<T, K extends keyof T> = {
[key in K]: T[key]
}
Solution by seungdeok #36595
// 你的答案
type MyPick<T, K extends keyof T> = {
[P in K]: T[P]
}
Solution by MrSissel #36577
// 你的答案
type MyPick<T extends Object, K extends keyof T> = {
[key in K]:T[key]
}
Solution by mola-fish #36572
type MyPick<T, K extends keyof T> = { [P in K]: T[P] }
Solution by ChemieAi #36546
type MyPick<T extends object, K extends keyof T> = {
[Key in K]: T[Key]
}
Solution by HadiMardanian #36518
type MyPick<T, K extends keyof T> = {
[key in K]: T[K]
}
Solution by TomMorningStar #36503
// your answers
Solution by TomMorningStar #36502
type MyPick<T extends object, K extends keyof T> = { [P in K]: T[K] }
Solution by shumik323 #36498
type MyPick<T, K extends keyof T> = {
[key in K]:T[key]
}
Solution by blueSky120 #36480
// your answers
Solution by Rigelumos #36445
type MyPick<T, K extends keyof T> = {
[U in K] : T[U]
}
Solution by gakki-san #36437
// your answers
type MyPick<T, K extends keyof T> = { [P in K]:T[P] }
Solution by alirezaprime #36408
type MyPick<T, K extends keyof T> = {
[P in K]: T[P];
};
Solution by syouzen #36379
// your answers
type MyPick<T, K extends keyof T> = {[J in K]: T[J] };
Solution by justBadProgrammer #36355
// 你的答案
type MyPick<T, K extends keyof T> = {
[key in K]:T[key]
}
Solution by ATravelerGo #36336