typescript - Vscode Typescript - 如何引用 types.d.ts
问题描述
我下载了screeps typescript starter并编写了代码。一切正常。然后我尝试将我的代码放在文件夹中(将“src/xx.ts”移动到“src/prototypes/xx.ts”)。VSCode 开始抛出如下错误:
'Creep'.ts(2339) 类型上不存在属性'isRemoteRole'
但是该属性是在 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"]
}
解决方案
我发现我的 types.d.ts 无效,这就是为什么没有检测到。由于某种原因,types.d.ts 顶部的导入导致它抛出一个不可见的错误。
我删除了:
import { ResourceTask } from "../screeps2/src/_models";
并将其替换为:
import("c:/Users/me/Desktop/screeps2/src/helper").ResourceTask
推荐阅读
- android - 如何在 Android 测试中等待 X 毫秒?
- android - 使用 Android BLE,我需要在读回字节数据时请求大 MTU,还是仅在写入时才需要?
- angular - 将 OneSignal 与 Angular 集成不要注册
- javascript - 同时计算多个集合中的文档
- css - 具有行和列全高的引导容器
- powershell - 如何从PowerShell中的GET-TIMEZONE函数响应中读取时区ID
- firebase - 我应该使用 Cloud Functions 制作 RESTful API 还是在应用程序中调用 Firebase 和 Firestore?
- python - Python中使用OLS的线性多元回归不起作用
- java - 构建 Geonetwork 时 Maven 构建失败
- java - Netbeans 12.0 Java 提示和亮点不起作用