TypeScript 从函数接口中选择调用签名 [英] TypeScript pick call signature from function interface
本文介绍了TypeScript 从函数接口中选择调用签名的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
有一个带有静态的函数接口:
There is a function interface with statics:
interface MyFunction {
(value: string): string;
a: string;
b: string;
}
我如何仅选择
调用签名(忽略a
和b
)?
How do I Pick
the call signature only (ignore a
and b
)?
推荐答案
您不能选择调用签名,因为它不是您界面的属性.
你可以做下一步:
You cannot Pick a call signature as it is not a property of your interface.
You can do next:
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>;
这篇关于TypeScript 从函数接口中选择调用签名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文