TypeScript Exclude

Exclude<T, U>,该工具类型能够从类型T中剔除所有可以赋值给类型U的类型。示例如下:

type T0 = Exclude<"a" | "b" | "c", "a">; // "b" | "c"
type T1 = Exclude<"a" | "b" | "c", "a" | "b">; // "c"
type T2 = Exclude<string | (() => void), Function>; // string

const x: T0 = "b";
const y: T1 = "c";
const z: T2 = "coolcou.com";

console.log(x)
console.log(y)
console.log(z)

输出结果:

TypeScript Exclude

酷客网相关文章:

赞(0)

评论 抢沙发

评论前必须登录!