【发布时间】:2020-07-12 04:59:51
【问题描述】:
当前设置
这是我的目录结构:
root
├──typings/ # currently empty
├──package.json
├──package-lock.json
├──tsconfig.json
└──main.ts
这是我的tsconfig.json:
{
"compilerOptions": {
"typeRoots": [
"./typings"
],
"types": ["Phaser"]
}
}
这是我的main.ts 文件:
let countdownNumber: Phaser.GameObjects.BitmapText;
然后我在终端中运行了以下命令:
tsc --traceResolution
我正在尝试在我的main.ts 文件中使用Phaser 作为全局变量。
预期行为:
应该发生的是 Phaser 不应该得到解决,因为编译器应该开始查看我的自定义文件夹 typings。
实际行为:
不知何故,它仍然得到解决。这就是它打印的内容:
类型参考指令“Phaser”已成功解析为“/Applications/XAMPP/xamppfiles/htdocs/phasertest/node_modules/Phaser/types/phaser.d.ts”,包 ID 为“phaser/types/phaser.d.ts” @3.22.0',主要:假。
我不知道它是如何找到它的,因为在我的 typeRoots 中,我没有指定 node_modules。
我尝试过的:
我试图排除 node_modules 文件夹,我想也许它们仍然会被编译,这就是发生这种情况的原因,但我无法使 exclude 与以下任何一个一起使用:
"exclude": ["node_modules/*"]"exclude": ["./node_modules/*"]"exclude": ["./node_modules"]
但这些都不起作用。
【问题讨论】:
-
Automatic Type Acquisition 也可能会干扰?
标签: javascript typescript typescript-typings typescript-generics tsconfig