TypeScript,我不能省略<someUnion,oneInterface>。为什么?

Jos*_*ang 0 typescript

请查看以下最小示例:

interface A {
  a: number;
}
interface B {
  b: number;
}
interface C {
  c: number;
}

type ABC = A | B | C;

type omitA = Omit<ABC, A>;

Run Code Online (Sandbox Code Playgroud)

在此处输入图片说明

我不能省略接口,但是,省略字符串属性可以正常工作。

如何排除该界面?

luk*_*ter 5

Omit类型是用于去除性能从类型(通过提供他们的名字作为字符串,数字或符号)。

您正在寻找的是Exclude,已在2.8版中添加

type ABC = A | B | C;

type omitA = Exclude<ABC, A>;
Run Code Online (Sandbox Code Playgroud)