【问题标题】:Vscode Typescript- How to reference types.d.tsVscode Typescript - 如何引用 types.d.ts
【发布时间】:2020-08-21 19:23:17
【问题描述】:

我下载了screeps typescript starter,并编写了代码。一切正常。然后我尝试将我的代码放在文件夹中(将“src/xx.ts”移动到“src/prototypes/xx.ts”)。 VSCode 开始抛出这样的错误:

“蠕变”类型上不存在属性“isRemoteRole”.ts(2339)

但是该属性是在 types.d.ts 中声明的。当我尝试使用 VScode 快速修复时,它会将属性声明添加到 index.d.ts 而不是 types.d.ts。这里有什么问题?

我尝试在 tsconfig 中明确指定类型文件的路径并重新启动 VSCode,但这似乎没有帮助。

我的 tsconfig.json:

{
  "compilerOptions": {
    "module": "esnext",
    "lib": ["esnext"],
    "target": "es2017",
    "moduleResolution": "Node",
    "outDir": "dist",
    "baseUrl": "src/",
    "sourceMap": true,
    "strict": true,
    "experimentalDecorators": true,
    "noImplicitReturns": true,
    "allowSyntheticDefaultImports": true,
    "allowUnreachableCode": false
  },
  "exclude": ["node_modules"],
  "types": ["src/types.d.ts"]
}

【问题讨论】:

    标签: typescript visual-studio-code .d.ts


    【解决方案1】:

    我发现我的 types.d.ts 无效,这就是为什么没有检测到。由于某种原因,types.d.ts 顶部的导入导致它抛出一个不可见的错误。

    我删除了:

    import { ResourceTask } from "../screeps2/src/_models";
    

    并将其替换为:

    import("c:/Users/me/Desktop/screeps2/src/helper").ResourceTask
    

    【讨论】:

      猜你喜欢
      • 2020-08-17
      • 2021-10-15
      • 2017-07-26
      • 2018-10-24
      • 2015-12-07
      • 2021-05-06
      • 2020-03-18
      • 2020-10-13
      • 1970-01-01
      相关资源
      最近更新 更多