相关疑难解决方法(0)

你能在TypeScript中扩展HTMLDivElement吗?

我是第一次制作基于DOM的游戏.我想扩展HTMLDivElement,但是在TypeScript中,HTMLDivElement是一个接口.

我想做这个伪类:

class QuizElement extends HTMLDivElement{

}
Run Code Online (Sandbox Code Playgroud)

对不起,如果这个问题很疯狂.我对DOM有些新意,只是想,我可以在任何其他环境中扩展任何视觉类,所以我想这里可行!

typescript

10
推荐指数
3
解决办法
6762
查看次数

如何让 Web Components 使用 TypeScript 为 IE11/Edge/Chrome/Firefox 进行编译?

设置了一个 Web 项目以使用 TypeScript/WebPack 后,我无法让 Google Chrome 运行结果:

在此处输入图片说明

错误如下: "Uncaught TypeError: Failed to construct 'HTMLElement': Please use the 'new' operator, this DOM object constructor cannot be called as a function."

我了解到转译到 ES5需要一个 shim,但我仍然无法让它工作。这可能是因为我不想在 HTML 中添加 <script> 元素,而是想import "../node_modules/@webcomponents/webcomponentsjs/webcomponents-bundle";在我的.ts文件中添加。

如何在不向 HTML 文件中添加 <script> 元素的情况下使其工作?

我从本教程中获取了我的tsconfig.jsonwebpack.config.js文件。

javascript google-chrome web-component typescript webpack-4

6
推荐指数
1
解决办法
3092
查看次数