我的angular应用程序遇到了一个奇怪的问题,我刚刚将AngularFire添加到了我的项目中,但是当我尝试将其放置时,它显示了以下错误:
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'.
我在Angular和AngularFire中是一个新手,我认为这是TypeScript问题,所以这是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"
]}}
有人可以帮我吗?
谢谢。
答案 0 :(得分:6)
您必须在tsconfig.json中设置一些选项。错误来自node_modules/@angular/fire/angularfire2.d.ts。
tsconfig:
{
//...
compilerOptions: {
"skipLibCheck": true,
//...
}
}
skipLibCheck:此选项用于跳过声明文件的类型检查。
答案 1 :(得分:4)
我找到了问题的核心,我的Ng版本是7.3.9,而AngularFire是6.0.0,我不得不将版本降级到5.4.2。这完美地解决了我的问题。
感谢开发人员的帮助。
建议:在向项目添加依赖项之前检查两个版本非常重要。
答案 2 :(得分:3)
如果您的Angular CLI:7.2.3版本
添加这些依赖项
“ @ angular / fire”:“ ^ 5.4.2”,
“ firebase”:“ ^ 6.6.2”,
“ firebase-admin”:“ ^ 8.9.2”,
“ fs-extra”:“ ^ 9.0.1”,
在package.json文件中,然后运行
npm install