【发布时间】:2021-07-17 15:54:10
【问题描述】:
我有一个简单的
type ExampleType = 'a' | 'b' | 'c';
使用方式如下:
from(from: ExampleType) {
return {
to: (to: ExampleType) => {
// move something from/to
},
}
}
我试图让“to-Function”只接受不是参数“from”中传递的值的值。 我尝试使用 Omit 和 Exclude,但它们都不接受动态值。
这可以在打字稿中实现吗?
我想像这样使用它
move(something).from('a').to('b'); // .to() should only accept 'b' and 'c'
如果 IDE 会为此提出正确的建议,那就太好了
【问题讨论】:
标签: typescript typescript-generics