Skip to content
Onsite

MyExclude<T, U>

EasyP1Coding

Implement the built-in Exclude<T, U> generic without using it.

MyExclude<T, U> removes from the union T every member that is assignable to U.

Tests your type must pass

type cases = [
  Expect<Equal<MyExclude<'a' | 'b' | 'c', 'a'>, 'b' | 'c'>>,
  Expect<Equal<MyExclude<'a' | 'b' | 'c', 'a' | 'b'>, 'c'>>,
  Expect<Equal<MyExclude<string | number | (() => void), Function>, string | number>>,
  Expect<Equal<MyExclude<'a' | 'b', 'z'>, 'a' | 'b'>>,
  Expect<Equal<MyExclude<'a' | 'b', 'a' | 'b'>, never>>,
]

Hints

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