javascript - TypeScript 中的 Typeof 参数对象

标签 javascript node.js

我基本上有这个:

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/

相关文章:

javascript - jQuery 克隆 div 中的事件 img 并使其成为 div 的背景图像

javascript - 在 Coffeescript 中调用方法并传递适当的上下文

javascript - 如何添加样式 - 如边距 - 来 react 组件?

javascript - mongoDB node.js findAndModify 麻烦

node.js - Node 服务器在超过 1000 个项目的对象上崩溃

javascript - append() 函数在网页中不起作用

javascript - 当特定元素具有相同的类名时,如何获取 jQuery 函数来处理它们?

node.js - 为 socket.io 和 SSL/WSS 配置 Apache

node.js - 类型错误 [ERR_INVALID_ARG_TYPE] : The "listener" argument must be of type Function

javascript - 尝试使用 Express 设置 cookie 时我做错了什么