Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/typescript/9.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/google-chrome/4.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从函数接口选取调用签名_Typescript - Fatal编程技术网

TypeScript从函数接口选取调用签名

TypeScript从函数接口选取调用签名,typescript,Typescript,有一个与statics的函数接口: interface MyFunction { (value: string): string; a: string; b: string; } 如何仅选择调用签名(忽略a和b)?您不能选择调用签名,因为它不是界面的属性。 接下来,您可以执行以下操作: interface MyFunction { (value: string): string; a: string; b: string; } type Callable&

有一个与statics的函数接口:

interface MyFunction {
  (value: string): string;
  a: string;
  b: string;
}

如何
仅选择调用签名(忽略
a
b
)?

您不能选择调用签名,因为它不是界面的属性。
接下来,您可以执行以下操作:

interface MyFunction {
    (value: string): string;
    a: string;
    b: string;
}

type Callable<T> = T extends (...args: any[]) => any ? (...args: Parameters<T>) => ReturnType<T> : never;

type MyFunctionCallSignature = Callable<MyFunction>;
接口函数{
(值:字符串):字符串;
a:弦;
b:弦;
}
类型Callable=T扩展(…参数:any[])=>any?(…args:Parameters)=>ReturnType:never;
类型MyFunctionCallSignature=Callable;

您不能
拾取它,因为您不能传递将选择它的
字符串
键,但是这里有一些构造的类型可以推断出正确的函数类型:

接口函数{
(值:字符串):字符串;
a:弦;
b:弦;
}
类型SignatureType=T扩展(…参数:推断R)=>any?R:从来没有;
类型CallableType any>=(…参数:SignatureType)=>ReturnType;
类型CallableOfMyFunction=CallableType;//类型(值:字符串)=>字符串

我不知道存在类型
参数。什么时候推出的?