1

我正在尝试从@types/webgl2我的项目中导入一些类型。我遵循了这里提到的每一条建议: TypeScript Typings give me "index.d.ts is not a module"

将此添加到顶部:import 'webgl2';

  • 我已经确定“ modeResolution”是“ true”在tsconfig.json
  • "types":["webgl2"]在我的tsconfig.json
  • 添加 "@types/webgl2": "0.0.4"devDependenciesdependenciespackage.json
  • 在我的项目文件夹中安装了 npm:
npm WARN package.json webgl@0.0.1 No README data
npm WARN package.json Dependency '@types/webgl2' exists in both dependencies and devDependencies, using '@types/webgl2@0.0.4' from  dependencies

我可以很容易地看到webgl2node_modules/@types我还可以在下面看到所有错误符号的声明:

declare var WebGl2RenderingContext {

我仍然收到这些错误:

(multiple lines)
Cannot find name 'WebGl2RenderingContext'. Did you mean 'WebGL2RenderingContext'?

对应:

const format = WebGl2RenderingContext.RED;
4

4 回答 4

4

通过修复拼写错误来解决。

于 2018-07-26T06:26:37.183 回答
1

在您的 tsconfig 中设置 typeRoot:

{
     "typeRoots": ["node_modules/@types"]
}
于 2018-07-26T06:13:05.603 回答
0

对于 NG9'ers,请尝试删除您的 package-lock.json 文件,然后:

npm i crypto
于 2020-04-01T16:14:33.433 回答
0

对我来说,我遇到了一个问题,其中types指定了tsconfig一些类型并没有自动添加到全局范围。

所以有问题的包是@types/dom-webcodecs,我像这样将它添加到 tsconfig

{
  "compilerOptions": {
    "types": [
      "dom-webcodecs",
      ...
    ]
  }
}

之后我可以访问这些类型。

这与另一个答案谈到的 typeRoots 不同。如果需要,您可以在此处探索差异。

于 2021-10-20T18:50:04.147 回答