成功编译了我的 TypeScript 项目后,我打算在 VS Code 的调试模式下使用ts-node
. 问题是,ts-node
找不到d.ts
我创建的文件(虽然tsc
没有问题)。
项目结构为:
/
conf/
dist/
src/
types/
package.json
tsconfig.json
tsconfig.json
相关条目是:
{
"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/**/*"
]
}
定义文件ts-node
找不到是src/types/global.d.ts
:
import { App } from '../App';
declare global {
namespace NodeJS {
interface Global {
app: App;
}
}
}
所以,尝试运行它,ts-node
我看到:
TSError: ⨯ Unable to compile TypeScript:
src/boot.ts(15,59): error TS2339: Property 'app' does not exist on type 'Global'.
如何在全球范围内解决它?我发现这/// <reference path="./types/global.d.ts" />
可以解决问题,但我必须在每个文件中使用global.app
.
我的 TypeScript 版本是 3.0.1