Skip to content
Onsite

PickByType<T, U>

MediumP2Coding

Implement PickByType<T, U>: build an object type with only the properties of T whose value type is assignable to U.

Tests your type must pass

interface Model {
  name: string
  count: number
  isReadonly: boolean
  isEnable: boolean
}

type cases = [
  Expect<Equal<PickByType<Model, boolean>, { isReadonly: boolean; isEnable: boolean }>>,
  Expect<Equal<PickByType<Model, string>, { name: string }>>,
  Expect<Equal<PickByType<Model, number>, { count: number }>>,
  Expect<Equal<PickByType<Model, Date>, {}>>,
]

Hints

TypeScript
Run and Submit type-check your solution against the tests.