My Current Directory Structure
Let me show you the layout of my files:
root
├──typings/ # currently empty
├──package.json
├──package-lock.json
├──tsconfig.json
└──main.ts
This is what my tsconfig.json
looks like:
{
"compilerOptions": {
"typeRoots": [
"./typings"
],
"types": ["Phaser"]
}
}
Inside my main.ts
file, I have the following line of code:
let countdownNumber: Phaser.GameObjects.BitmapText;
After running the command below in terminal:
tsc --traceResolution
My intention was to use Phaser
as a global variable in my main.ts
file.
Expected Outcome:
My expectation was that Phaser
would not be resolved because the compiler should search within my custom folder typings
.
Actual Result:
To my surprise, Phaser
still got resolved. Here is the information it provided:
Type reference directive 'Phaser' was successfully resolved to '/Applications/XAMPP/xamppfiles/htdocs/phasertest/node_modules/Phaser/types/phaser.d.ts' with Package ID 'phaser/types/[email protected]', primary: false.
I am unsure as to how it found it, considering that I did not specify node_modules
in my typeRoots
.
My Attempts to Resolve:
In an effort to exclude the node_modules
folder, I experimented with different configurations of the exclude
option, but unfortunately, none of them yielded the desired result:
"exclude": ["node_modules/*"]
"exclude": ["./node_modules/*"]
"exclude": ["./node_modules"]
Regrettably, none of these approaches were successful.