【发布时间】:2018-07-25 09:37:01
【问题描述】:
我在使用 typescript 和 @types/react 时遇到了一个奇怪的构建问题。我有两个 typescript 配置文件:一个用于使用 react 的文件,一个用于不使用 react 的文件。在构建不使用 react 的项目部分时,我看到以下错误:
node_modules/@types/react/index.d.ts(3508,58):错误 TS2304:不能 找到名称“HTMLDialogElement”。 node_modules/@types/react/index.d.ts(3508,78):错误 TS2304:不能 找到名称“HTMLDialogElement”。 node_modules/@types/react/index.d.ts(3782,72):错误 TS2304:不能 找到名称“HTMLDialogElement”。 node_modules/@types/react/index.d.ts(3782,92):错误 TS2304:不能 找到名称“HTMLDialogElement”。
我能够通过一个最小的示例重现该错误:
node_modules/typescript/bin/tsc typescript/foo.ts --outDir static/js/src --module none
typescript/foo.ts 文件是我用来重现问题的最小文件,并且故意缩短:
function printNumber(n: number) {
console.log(n);
}
let x = 3;
x *= 4;
printNumber(x);
请注意,foo.ts 没有任何引用来做出任何反应。最奇怪的部分是当我卸载 @types/react 时,错误消息消失了。
发生了什么事?
编辑:我找到了this issue,它在 tsc 版本 > 2.3.2 时出现。我将 tsc 降级到 2.3.2 版本,但问题仍然存在。
【问题讨论】:
-
您使用的是什么版本的打字稿?我有一个类似的问题,当我更新到 2.7.x 时它就消失了
-
@Ziggy typescript v 2.3.2
-
遇到同样的问题。
-
你能提供一个这个错误的最小例子吗? (带有配置)
-
从今天开始面临同样的问题......
标签: javascript reactjs typescript