我正在使用Typescript 3.1将Ionic 3应用程序升级到Ionic 4,但是我遇到了Typescript路径的麻烦。
我的tsconfig.json
中有以下内容:
"paths": {
"@models": [ "src/models/index" ],
"@services": [ "src/services/index" ],
"@shared": [ "src/shared/index" ],
"@app/*": [ "src/app/*" ],
"@models/*": [ "src/models/*" ],
"@services/*": [ "src/services/*" ],
"@shared/*": [ "src/shared/*" ]
},
,这在我的src/tsconfig.app.json
中:
"paths": {
"@models": [ "models/index" ],
"@services": [ "services/index" ],
"@shared": [ "shared/index" ],
"@app/*": [ "app/*" ],
"@models/*": [ "models/*" ],
"@services/*": [ "services/*" ],
"@shared/*": [ "shared/*" ]
},
Visual Studio中检测到文件就好了,不给我任何样的错误,但是当我运行ionic serve
,它无法找到任何文件。我收到如下错误:
[ng] src/models/jobs/job.model.ts(1,33): error TS2307:
Cannot find module '@models/customers/customer.model'.
该行:
import { ICustomerModel } from "@models/customers/customer.model";
我如何获得ionic serve
以遵守我的Typescript路径?
答案 0 :(得分:0)
我找到了答案。
我需要添加
"baseUrl": ".",
到editorOptions。添加完之后,它就起作用了。
完整tsconfig.app.json
:
{
"extends": "../tsconfig.json",
"compilerOptions": {
"baseUrl": ".",
"paths": {
"@models": [ "models/index" ],
"@services": [ "services/index" ],
"@shared": [ "shared/index" ],
"@app/*": [ "app/*" ],
"@models/*": [ "models/*" ],
"@services/*": [ "services/*" ],
"@shared/*": [ "shared/*" ]
},
"outDir": "../out-tsc/app",
"module": "es6",
"types": [ "node" ]
},
"exclude": []
}