让我们说我们有
type U = A | B | C我们需要U型没有一些选择
function f<T option U>(u: U): U without T {...}我们该如何表达
发布于 2019-07-04 10:43:55
是的,使用从stadard库排除。
type U = 'a' | 'b' | 'c';
type nonA = Exclude<U, 'a'>; // 'b' | 'c'为了你的职责
function f<T extends U>(u: U): Exclude<U,T> {...}https://www.typescriptlang.org/docs/handbook/release-notes/typescript-2-8.html#conditional-types
发布于 2019-07-04 11:09:55
100%工作实例
function withoutType<U, T extends U>(u: U) {
return u as Exclude<U, T>;
}
type Union = string | number | Function;
let x = 5;
let y = withoutType<Union, Function>(x); // let x: string | number;https://stackoverflow.com/questions/56884345
复制相似问题