使用路径引用文件路径以外的文件夹中的打字的Typescript
我遇到的情况是,库文件的路径与该库的打字文件的位置不同。具体地说,我将库文件放在一个文件夹中,但我尝试使用节点模块中@types文件夹中的打字。我想知道是否可以使用tsconfig中的path属性来处理这个问题 例如: src/app.ts使用路径引用文件路径以外的文件夹中的打字的Typescript,typescript,Typescript,我遇到的情况是,库文件的路径与该库的打字文件的位置不同。具体地说,我将库文件放在一个文件夹中,但我尝试使用节点模块中@types文件夹中的打字。我想知道是否可以使用tsconfig中的path属性来处理这个问题 例如: src/app.ts import Chart from './lib/Chart.min.js'; // <-- Says it cannot find module 从“./lib/Chart.min.js”导入图表;//您不需要在node\u modules目录下的
import Chart from './lib/Chart.min.js'; // <-- Says it cannot find module
从“./lib/Chart.min.js”导入图表;//您不需要在node\u modules
目录下的@types的typescript配置中提供路径别名。只需从tsconfig中删除path prop,它就可以作为import x from'chart'
或类似的内容导入。这里的问题是,在编译的文件中,路径必须是。/lib/chart.min.js
。如果我删除.ts文件中的。/lib/
,那么它也会在编译文件中消失。
{
"compilerOptions": {
"module": "amd",
"target": "es5",
"moduleResolution": "node",
"sourceMap": false,
"outDir": "./FileCabinet/SuiteScripts/PowerTrends",
"rootDir": "./src",
"lib": [
"es5",
"es2015",
"dom",
"es2017"
],
"baseUrl": ".",
"paths": {
"./lib/Chart.min.js": ["node_modules/@types/chart.js"] // <-- This doesn't seem to work
}
},
"compileOnSave": true,
"exclude": [
"node_modules"
]
}