我在 tsconfig.json 中定义的路径不起作用。
我使用 Ionic 4 启动了一个项目,希望避免导入中出现丑陋的路径。我找到了有关修改 tsconfig.json 的信息,我就这么做了。我已经找到了这些答案: How to use paths in tsconfig.json? 并且 无法解析 tsconfig 路径
所以我的 tsconfig.json 看起来像这样:
{
"compileOnSave": false,
"compilerOptions": {
"baseUrl": "./src",
"outDir": "./dist/out-tsc",
"sourceMap": true,
"declaration": false,
"module": "es2015",
"moduleResolution": "node",
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"importHelpers": true,
"target": "es5",
"typeRoots": [
"node_modules/@types"
],
"lib": [
"es2018",
"dom"
],
"paths": {
"@services/*": ["app/services/*"],
"@data/*": ["app/data/*"]
}
}
}
Run Code Online (Sandbox Code Playgroud)
我访问一个在我的服务中指定用户的类:
import { User } from '@data/User';
Run Code Online (Sandbox Code Playgroud)
User 类如下所示:
export class User {
...
} …Run Code Online (Sandbox Code Playgroud) single-page-application typescript ecmascript-6 ionic-framework angular