我对联合类型和
Exclude
存在问题(playground 链接)。type Foo = {
data: string;
otherData: number;
};
type Bar = Omit<Foo,'otherData'>
// type Bar = { data: string; }; // Even this is not working
type FooBar = Foo | Bar;
type ShouldBeFoo = Exclude<FooBar, Bar>; // Not working
// ShouldBeFoo = never
type ShouldBeBar = Exclude<FooBar, Foo>; // Somehow working
// ShouldBeBar = { data: string }
我是否遗漏了与联合类型和/或 Exclude
相关的内容?
我也尝试过使用 TS 4.4 和 4.2,结果相同。
注意:
我们使用类型保护发现了这个问题,您可以在此处 playgorund 查看。