, Exclude<"a" | "b" | "c", "a">>>, Expect, Exclude<"a" | "b" | "c", "a" | "b">>>, Expect void), Function>, Exclude void), Function>>>, ] /* _____________ Further Steps _____________ */ /* > Share your solutions: https://tsch.js.org/43/answer > View solutions: https://tsch.js.org/43/solutions > More Challenges: https://tsch.js.org */"> , Exclude<"a" | "b" | "c", "a">>>, Expect, Exclude<"a" | "b" | "c", "a" | "b">>>, Expect void), Function>, Exclude void), Function>>>, ] /* _____________ Further Steps _____________ */ /* > Share your solutions: https://tsch.js.org/43/answer > View solutions: https://tsch.js.org/43/solutions > More Challenges: https://tsch.js.org */"> , Exclude<"a" | "b" | "c", "a">>>, Expect, Exclude<"a" | "b" | "c", "a" | "b">>>, Expect void), Function>, Exclude void), Function>>>, ] /* _____________ Further Steps _____________ */ /* > Share your solutions: https://tsch.js.org/43/answer > View solutions: https://tsch.js.org/43/solutions > More Challenges: https://tsch.js.org */">
/*
  43 - Exclude
  -------
  by Zheeeng (@zheeeng) #easy #built-in
  
  ### Question
  
  Implement the built-in Exclude<T, U>
  > Exclude from T those types that are assignable to U
  
  > View on GitHub: <https://tsch.js.org/43>
*/

/* _____________ Your Code Here _____________ */

type MyExclude<T, U> = any

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

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

/* _____________ Further Steps _____________ */
/*
  > Share your solutions: <https://tsch.js.org/43/answer>
  > View solutions: <https://tsch.js.org/43/solutions>
  > More Challenges: <https://tsch.js.org>
*/

내장 exclude를 구현해보자.

  • exclude의 동작을 생각하면 간단한다.
  • Exclude<T, U> -- U에 할당할 수 있는 타입은 T에서 제외
type MyExclude<T, U> = T extends U ? never : T