- 此问题在此处已有答案**:
Is there a method to directly exclude types from a union type in Typescript?(1个答案)
TypeScript Filter out types from type(1个答案)
1年前关闭。
我喜欢的类型:
export type Example = ExampleOne | ExampleTwo | ExampleThree;
如何创建一个只包含ExampleOne
或ExampleTwo
的新类型ExampleX
?
我试过:
export type ExampleX = Omit<Example, 'ExampleThree'>;
但那不管用?
1条答案
按热度按时间uxh89sit1#
您要查找的是
Exclude
,而不是Omit
:通过从UnionType中排除所有可分配给ExcludedMembers的联合成员来构造类型。
因此:
Playground链接