Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/extjs/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Typescript 如果IsSomething<;T>;这是真的吗?_Typescript - Fatal编程技术网

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>) => {
  // ...
};