Having compiled my TypeScript project successfully, I intended to run it in VS Code's debug mode using ts-node
. Problem is, ts-node
can't find d.ts
files I created (while tsc
has no problem with it).
Project structure is:
/
conf/
dist/
src/
types/
package.json
tsconfig.json
tsconfig.json
relevant entries are:
{
"compilerOptions": {
"target": "es2017",
"module": "commonjs",
// "lib": [],
"sourceMap": true,
"outDir": "dist",
"rootDir": "src",
"moduleResolution": "node",
"baseUrl": ".",
"paths": {
"*": [
"node_modules/*",
"src/types/*"
]
},
// "rootDirs": [],
// "typeRoots": [],
// "types": [],
},
"include": [
"src/**/*"
]
}
The definition file ts-node
can't find is src/types/global.d.ts
:
import { App } from '../App';
declare global {
namespace NodeJS {
interface Global {
app: App;
}
}
}
So, trying to run it with ts-node
I see:
TSError: ⨯ Unable to compile TypeScript:
src/boot.ts(15,59): error TS2339: Property 'app' does not exist on type 'Global'.
How to resolve it globally? I've found that /// <reference path="./types/global.d.ts" />
does the trick but I'd have to repeat it in every file using global.app
.
My TypeScript version is 3.0.1
--files
does the trick. I don't know however whytypeRoots
doesn't. It is the way to go according to github.com/TypeStrong/ts-node#help-my-types-are-missing but I tried it and it didn't help. Anyway,--files
worked but I had to find a way to wire it into VS Code'slaunch.json
. Finally, I made ats-node.js
file in the project root that contained only:require('ts-node').register({ files: true })
and referenced it inlaunch.json
:"runtimeArgs": [ "-r", "./ts-node.js" ]
. Thanks a lot for your help! – Scherer