我基本上有这个:
function foo(){
// literally pass the arguments object into the pragmatik.parse method
// the purpose of pragmatik.parse is to handle more complex variadic functions
const [a,b,c,d,e] = pragmatik.parse(arguments);
// now we have the correct arguments in the expected location, using array destructuring
}
所以我们有了 pragmatik.parse
方法:
function parse(args){
// return parsed arguments
}
现在我想使用 TypeScript 来定义类型,我所知道的是参数是一个对象:
function parse(args: Object){
}
所以我的问题是:TypeScript 是否为 JS 中的 arguments
对象提供定义或类型?抱歉,这有点元,但请耐心等待,我问的是理智的。
最佳答案
我的 Webstorm IDE 表明这可能是 IArguments
,它由位于某处的 lib/es6/d.ts
提供。也许有人可以验证这是正确的,但我相当确定。
所以答案是:
function parse(args: IArguments){
}
完整的签名是:
function parse(args: IArguments) : Array<any> {
}
因为 parse 方法返回一个通用数组
关于javascript - TypeScript 中的 Typeof 参数对象,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42572393/