Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Error TS2344: Type 'T[K]' does not satisfy the constraint

I am having a weird issue with my angular application, I just added AngularFire to my project, however when I try to put it up, it displays the following error:

ERROR in nodae_modules/@angular/fire/angularfire2.d.ts(37,49): error TS2344: Type 'T[K]' does not satisfy the constraint '(...args: any[]) => any'.
node_modules/@angular/fire/angularfire2.d.ts(40,49): error TS2344: Type 'T[K]' does not satisfy the constraint '(...args: any[]) => any'.
node_modules/@angular/fire/angularfire2.d.ts(48,78): error TS2344: Type 'T[K]' does not satisfy the constraint '(...args: any[]) => any'.
node_modules/@angular/fire/angularfire2.d.ts(48,107): error TS2344: Type 'T[K]' does not satisfy the constraint '(...args: any[]) => any'.
node_modules/@angular/fire/angularfire2.d.ts(50,75): error TS2344: Type 'T[K]' does not satisfy the constraint '(...args: any[]) => any'.
node_modules/@angular/fire/angularfire2.d.ts(50,96): error TS2344: Type 'T[K]' does not satisfy the constraint '(...args: any[]) => any'.

I am quite new in Angular and AngularFire, I assumed the it's kind of TypeScript issue so here's the tsconfig.json

{
 "compileOnSave": false,
 "compilerOptions": {  
 "baseUrl": "./",
 "outDir": "./dist/out-tsc",
 "sourceMap": true,
 "declaration": false,
 "module": "esnext",
 "moduleResolution": "node",
 "emitDecoratorMetadata": true,
 "experimentalDecorators": true,
 "importHelpers": true,
 "target": "es5",
 "typeRoots": [
  "node_modules/@types"
],
"lib": [
  "es2018",
  "dom"
]}}

Can somebody help me with this?

Thanks in advance.

like image 861
HeyBaldur Avatar asked May 11 '20 17:05

HeyBaldur


Video Answer


3 Answers

You have to set some options in tsconfig.json. The errors are from node_modules/@angular/fire/angularfire2.d.ts.

tsconfig:

{
  //...
  compilerOptions: {
    "skipLibCheck": true,
    //...
  }
}

skipLibCheck: This option is to skip type checking of declaration files.

like image 150
Jasdeep Singh Avatar answered Oct 23 '22 10:10

Jasdeep Singh


I found the core of the problem, my Ng version is 7.3.9 and AngularFire was 6.0.0 I had to downgrade the version to 5.4.2. This solved my problem perfectly.

Thank you developers for your help.

Advice: It's really important to check both versions before adding dependencies to the project.

like image 22
HeyBaldur Avatar answered Oct 23 '22 10:10

HeyBaldur


If your Angular CLI: 7.2.3 version

add these dependencies
"@angular/fire": "^5.4.2",
"firebase": "^6.6.2",
"firebase-admin": "^8.9.2",
"fs-extra": "^9.0.1",

in package.json file and run
npm install

like image 34
Udula Indunil Avatar answered Oct 23 '22 09:10

Udula Indunil