Skip to content

实现 Exclude

实现内置的Exclude <T, U>类型,但不能直接使用它本身。

从联合类型T中排除U的类型成员,来构造一个新的类型。

例如:

ts
type Result = MyExclude<'a' | 'b' | 'c', 'a'> // 'b' | 'c'
  • 在下方编写代码:
查看解答
ts
type MyExclude<T, U> = T extends U ? never : T

Released under the MIT License.