typescript - 更新到 Angular 10 后无法找到命名空间
所有东西在 Angular 8 上都能运行,我先升级到 Angular v9,然后升级到 Angular v10,当我尝试运行我的项目时,所有命名空间都受到了影响,我希望可能有解决这个问题的方法,而不是将所有内容移动到独立的接口,我在下面留下所有细节。
namespace Auth {
export interface Token {
access_token: string;
token_type: string;
expires_in: number;
refresh_token: string;
scope: string;
}
export interface Login {
email: string;
password: string;
app_code?: number;
}
}
错误:
error TS2503: Cannot find namespace 'Auth'. login(credentials: Auth.Login) {}
我尝试添加 export、export declare 和 declare,但没有结果。
tsconfig.base.json
{
"compileOnSave": false,
"compilerOptions": {
"baseUrl": "./",
"downlevelIteration": true,
"outDir": "./dist/out-tsc",
"sourceMap": true,
"declaration": false,
"module": "esnext",
"moduleResolution": "node",
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"importHelpers": true,
"target": "es2018",
"typeRoots": [
"node_modules/@types"
],
"lib": [
"es2018",
"dom"
]
}
}
答案#1
我遇到了类似的问题,把 Angular 升级到了 12。然后我收到了大量“找不到命名空间”的错误信息。在我的情况下,更新更改了 tsconfig.app.json 文件,并在其中扩展了以下部分:
"include": [
"src/**/*.d.ts"
]
由于我的 tsconfig.app.json 文件已经位于 src 文件夹中,我需要将提到的部分修改为:
"include": [
"**/*.d.ts"
]
而这解决了问题!
