[Typescript Challenges] 6 Easy - Exclude

Implement the built-in Exclude<T, U>

For example:

type Result = MyExclude<'a' | 'b' | 'c', 'a'> // 'b' | 'c'

 

/* _____________ Your Code Here _____________ */

type MyExclude<T, U> = T extends U ? never: T


/* _____________ Test Cases _____________ */
import type { Equal, Expect } from '@type-challenges/utils'

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>>,
]

 

posted @ 2022-09-02 01:39  Zhentiw  阅读(25)  评论(0编辑  收藏  举报