可以用泛型来约束 type Not200<T> = T extends 200 ? never : number 演示使用 // 以下两种方式都可以 // declare function fn<T extends Not200<U>, U = T>(value: T): void; declare function fn<T>(value: T & Not200<T>): void; fn(200); // error fn(201); // ok... 在 TS Playground Link 中查看 参考 https://github.com/microsoft/...
可以用泛型来约束
演示使用
在 TS Playground Link 中查看
参考