javascript - typescript 参数数量错误

标签 javascript typescript

快速提问,我相信有人会快速回答这个问题。

我正在尝试使用文档。

document.createElement("button", "option");

由于第二个参数, typescript 不喜欢这个,它提示它只期望一个参数而不是两个参数被传递。在 vanilla JS 中,两个参数是可以接受的。

如何让 typescript 编译器允许这样做?

最佳答案

看起来标准定义不允许这样做,而且似乎是错误的。

我想 github 上的一个 bug 应该是正常的。

与此同时,作为 hack,您可以将函数保存为另一种类型。例如。

let createElement: (tagname: string, options: string) => HTMLElementTagNameMap = document.createElement;

关于javascript - typescript 参数数量错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45166657/

相关文章:

javascript - jQuery Roundabout - 元素位置错误

javascript - impress.js - 元素符号列表

javascript - 从模板字符串/文字中获取元素的 ID

javascript - 我的表格标题分为两行文本,我不明白为什么

javascript - 将 httpClient 答案转换为模型对象 [Angular 6]

javascript - 如何将 "15.90 €"这样的文本转换为 "1590"这样的数字?

javascript - 如何在 Ionic 中使用 CORS 编写 Angular 2 服务?

angular - ActivatedRoute 在服务中不起作用

javascript - Javascript中如何从三个数字中找到所需的数字?

typescript - webpack-Typescript source-map,ts的源文件就是编译后的js文件