简体   繁体   中英

Cannot find namespace after updating to Angular 10

Everything was working on Angular 8, I started updating first to Angular v9, then to Angular v10, and when I tried to run my project, all namespaces were affected, I hope maybe there is a solution to this issue instead of moving everything to an isolated Interface, I leave all the details below.

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:

error TS2503: Cannot find namespace 'Auth'. login(credentials: Auth.Login) {}

I tried adding export and export declare and declare but no results.

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"
    ]
  }
}

I had a similar issue, upgraded Angular up until 12. Then I got a bunch of "Cannot find namespace" error messages. In my case, the update changed the tsconfig.app.json file, and extended it with the following part:

 "include": [
    "src/**/*.d.ts"
  ]

Since my tsconfig.app.json file was located already in the src folder I needed to modify the mentioned part to become:

"include": [
   "**/*.d.ts"
]

And this resolved the issue!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM