Reputation: 595
env
with angular application, ng test
fails if I added types in compileroption in tsconfig.json.
errors are like
Cannot find name 'it'. Do you need to install type definitions for a test runner? Try `npm i @types/jest` or `npm i @types/mocha` and then add `jest` or `mocha` to the types field in your tsconfig.
S2304: Cannot find name 'expect'
my tsconfig is as below.
tsconfig.json
{
"compileOnSave": false,
"compilerOptions": {
"baseUrl": "./",
"outDir": "./dist/out-tsc",
"sourceMap": true,
"declaration": false,
"downlevelIteration": true,
"experimentalDecorators": true,
"module": "esnext",
"moduleResolution": "node",
"importHelpers": true,
"target": "es2015",
"lib": [
"es2018",
"dom"
]
},
"angularCompilerOptions": {
"fullTemplateTypeCheck": true,
"strictInjectionParameters": true,
"types": ["node"], // <= this part
}
}
I know if I remove that types
, then it works. But actually because of package which I use, I need to have it.
I hope someone has any knowledge about such behavior.
Upvotes: 0
Views: 702
Reputation: 595
Answer myself
remove types from tsconfig.json
and add it in tsconfig.app.json
tsconfig.json
// "types": ["node"], // remove
tsconfig.app.json
{
"extends": "./tsconfig.json",
"compilerOptions": {
"outDir": "./out-tsc/app",
"types": ["node"] // <= add
},
"files": [
"src/main.ts",
"src/polyfills.ts"
],
"include": [
"src/**/*.d.ts"
]
}
Upvotes: 1
Reputation: 144
In official google documentation there is no types option inside angularCompilerOptions property : exhaustive list of available options :
if u need node types you can just use npm i @types/node to install them and the types are added under this hierarchy :
{
"compilerOptions": {
"types" : ["node", "lodash", "express"]
}
}
Upvotes: 0