我在Node项目中使用TypeScript 2.0。 Node中的函数具有name属性。我试过扩展TypeScript Function接口来声明属性,如:
interface Function
{
name: string
}
interface IAsyncInfo {
name: string,
args: any[],
func: (...args: any[]) => any
}
var info: IAsyncInfo;
var name = info.func.name
但TypeScript仍在最后一行抱怨:
Property 'name' does not exist on type (...args: any[]) => any
然后我尝试了:
var name = (info.func as Function).name
但TypeScript抱怨
type '(...args: any[]) => any' cannot be converted to type 'Function'
答案 0 :(得分:0)
我真的不知道你在尝试什么。
你想要这样的东西吗?
interface IAsyncInfo {
name: string;
args: any[];
func(...args: any[]): any;
}
var info: IAsyncInfo;
var test = info.func.name;