在tsc成功编译项目时,ts-node会忽略d.ts文件 [英] ts-node ignores d.ts files while tsc successfully compiles the project
问题描述
已经成功编译了我的TypeScript项目,我打算使用ts-node
在VS Code的调试模式下运行它.问题是,ts-node
找不到我创建的d.ts
文件(而tsc
没问题).
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).
项目结构为:
/
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
运行它,我看到了:
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'.
如何在全球范围内解决该问题?我发现/// <reference path="./types/global.d.ts" />
可以解决问题,但是我必须使用global.app
在每个文件中重复进行此操作.
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
.
我的TypeScript版本是3.0.1
My TypeScript version is 3.0.1
推荐答案
ts-node --files src/boot.ts
ts-node在7.0.0中,默认情况下不要在启动时从tsconfig.json
加载文件,您应指定--files
ts-node in 7.0.0, default do not Load files from tsconfig.json
on startup, you should specific --files
这篇关于在tsc成功编译项目时,ts-node会忽略d.ts文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!