Typescript 如果IsSomething<;T>;这是真的吗?
我有一个复杂的泛型类型Typescript 如果IsSomething<;T>;这是真的吗?,typescript,Typescript,我有一个复杂的泛型类型IsInterest,根据我给它的T类型,它会变成true或false: type IsInteresting<T> = (/* ... */) ? true : false; 如果您以这种方式稍微更改IsInterest: type IsInteresting<T> = (/* ... */) ? T : never; 类型IsInterest=(/*…*/)?T:从来没有; 然后,您可以按如下方式键入函数: const operateOnI
IsInterest
,根据我给它的T
类型,它会变成true
或false
:
type IsInteresting<T> = (/* ... */) ? true : false;
如果您以这种方式稍微更改
IsInterest
:
type IsInteresting<T> = (/* ... */) ? T : never;
类型IsInterest=(/*…*/)?T:从来没有;
然后,您可以按如下方式键入函数:
const operateOnInterestingValue = <T>(value: IsInteresting<T>) => {
// ...
};
const operateOnInterestingValue=(值:IsInteresting)=>{
// ...
};
如果您试图使用一个变量调用
operateOnInterestingValue
,而该变量的IsInteresting
将解析为never
,编译器将对此进行投诉,抱歉延迟!非常感谢,这很有效!!
const operateOnInterestingValue = <T>(value: IsInteresting<T>) => {
// ...
};