00004-easy-pick

Back

// 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

type MyPick<T, K extends keyof T> = { [key in K]: T[key] }

Solution by asylbekduldiev #36330

// your answers

Solution by Arkadiy2907 #36324

type MyPick<T, K extends keyof T> = {
  [P in K]: T[P];
}

Solution by 1Alex4949031 #36306

type MyPick<Obj, Key extends keyof Obj> = {
    [key in Key]: Obj[key]
}

Solution by Timur000101 #36304

// 여기 풀이를 입력하세요
type MyPick<T, K extends keyof T> = {
  [P in K] : T[P]
}

Solution by ExceptAnyone #36288

// @ts-expect-error
type MyPick<T, K> = Omit<T, keyof Omit<T, K>>;

Solution by Jace254 #36262

interface Todo {
  title: string
  description: string
  completed: boolean
}

type Mypick<T extends Todo, K extends keyof T> = {
  [Key in K] : T[K]
}

type TodoPreview = Mypick<Todo, 'completed'>

const todo: TodoPreview = {
    title: 'Clean room',
    completed: false,
}

So I'm have expiriance with coding, but don't touch typescript deepth. I'm never use power of typescript full. Btw I don't write everywhere type any, but this task need a little more knowledges. So, I go to internet and start search more information about this. This was funny 😁

Solution by Burunduckc #36259

type MyPick<T, K extends keyof T> = {
  [key in K]: T[key]
}

Solution by bemyexe #36250

// 你的答案
type MyPick<T, K extends keyof T> = {
  [key in K]:T[key]
}

Solution by destinyliu3 #36219

// your answers

type MyPick<T, K extends keyof T> = { [k in K]: T[k] }

Solution by lxy2222 #36198

type MyPick<T, K extends keyof T> = {
  [key in K]: T[key];
}

Solution by tjd985 #36185

// your answers

type MyPick<T, K extends keyof T> = { [P in K]: T[P] }

Solution by asylbekduldiev #36159

// your answers

type MyPick<T, K extends keyof T> = { [P in K]: T[P] }

Solution by EvgeniyKoch #36118

type MyPick<T, K extends keyof T> = {
  [U in K]: T[U];
};

Solution by buglavecz #36084

// ============= Test Cases =============
import type { Equal, Expect } from './test-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
}


// ============= Your Code Here =============
type MyPick<T, K extends keyof T> = {
  [P in K]: T[P]
}

Solution by LittleBlacky #36055

type MyPick<T, K extends keyof T> = {
  [k in K] : T[k]
}

Solution by tungulin #36046

type MyPick<T, K extends keyof T> = Omit<T, Exclude<keyof T, K>>

Solution by karazyabko #36022

type MyPick<T, K extends keyof T> = {[k in keyof T & K]: T[k]}

Solution by KimKyuHoi #36003

// 여기 풀이를 입력하세요
type MyPick<T, K extends keyof T> = {
  [P in K]: T[P]
}

Solution by krokerdile #35981

type MyPick<T, K extends keyof T> = {[k in K]: T[k]};

Solution by Sedong-Choi #35974

type MyPick<T, K extends keyof T > = {[k in K]: T[k]};

Solution by codingaring #35923

type MyPick<T, K extends keyof T> = {
  [key in K]: T[key]
}

/* _____________ 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'>,
]

Solution by pytest5 #35896

type MyPick<T, K extends keyof T> = {[P in keyof T as P extends K ? P : never]: T[P]}

Solution by dienphamvan #35880

type MyPick<T, K extends keyof T > = {
  [k in K] : T[k]
}

Solution by HelloWook #35833

// 你的答案
type MyPick<T, K extends keyof T> = {
  [P in  K]: T[P]
}

Solution by reonce #35818

// 你的答案
type MyPick<T, K> = {
  [key in K extends keyof T ? K : never]: T[key]
}

Solution by naruto-823 #35782