After upgrade to Angular 9 cannot find variable in typings file
Had the same problem after migrating from Angular 7 to Angular 9.
I personally just had to add one line in tsconfig.app.json
.
Before:
{
"extends": "../tsconfig.json",
"compilerOptions": {
"outDir": "../out-tsc/app",
"types": [
"node"
]
},
"files": [
"main.ts",
"polyfills.ts"
],
"include": [
"src/**/*.d.ts"
]
}
After:
{
"extends": "../tsconfig.json",
"compilerOptions": {
"outDir": "../out-tsc/app",
"types": [
"node"
]
},
"files": [
"main.ts",
"polyfills.ts"
],
"include": [
"src/**/*.d.ts",
"typings.d.ts" // add this line
]
}
I assumed you already made changes in tsconfig.json
before migrating to Angular 9. If not, here it is:
{
...
"compilerOptions": {
...
"typeRoots": [
"node_modules/@types",
"src/typings.d.ts"
],
...
}
}
I had exactly the same problem as the author - after upgrade to Angular 9, my local type definitions were no longer found.
In Angular 8, I added references to them in tsconfig.json
"typeRoots": [
"node_modules/@types",
"../src/typings/my-lib/index.d.ts"
"node_modules/@types"
]
After upgrading to Angular 9, my-lib
was no longer found.
I generated a new app using Angular 9 CLI, and found that 2 files reside in different locations:
src/tsconfig.app.json
->tsconfig.app.json
src/tsconfig.spec.json
->tsconfig.spec.json
I made similar change in my migrated project, updated references to these files in angular.json
, and corrected pointers to other files in tsconfig.app.json
and tsconfig.spec.json
As a result, my tsconfig.app.json
looks like:
{
"extends": "./tsconfig.json",
"compilerOptions": {
"outDir": "./out-tsc/app",
"types": ["jest"]
},
"files": [
"src/main.ts",
"src/polyfills.ts"
],
"include": [
"src/**/*.d.ts"
]
}
Note that all d.ts
files placed under src
directory will be pulled in automatically (no reference in typeRoots
section of tsconfig.json
is necesssary)