【问题标题】:error TS2314: Generic type 'ModuleWithProviders<T>' requires 1 type argument(s)错误 TS2314:通用类型“ModuleWithProviders<T>”需要 1 个类型参数
【发布时间】:2020-12-06 22:55:27
【问题描述】:
ERROR in node_modules/@angular/fire/firestore/firestore.module.d.ts:7:74 - error TS2314: Generic type 'ModuleWithProviders<T>' requires 1 type argument(s).
    
    7     static enablePersistence(persistenceSettings?: PersistenceSettings): ModuleWithProviders;

我在将 firebase 添加到我的 Angular 10 项目时遇到上述错误。 (旧的 Angular 9 项目没有问题)

我添加 Firebase 的步骤

  1. npm install firebase @angular/fire --save

  2. ng 添加@angular/fire

  3. 更新了 environment.ts

  production: false,
  firebase: {
    apiKey: <secret> ,
    authDomain: <secret>,
    databaseURL: <secret>,
    projectId: <secret>,
    storageBucket: <secret>,
    messagingSenderId: <secret>,
    appId: <secret>,
    measurementId: <secret>
  }
}; 
  1. 更新了 app.module.ts
// Firebase imports
import { AngularFireModule } from '@angular/fire';
import { AngularFirestoreModule} from '@angular/fire/firestore';
import { environment } from '../environments/environment';

@NgModule({
  declarations: [
    AppComponent
  ],
  imports: [
    QuicklinkModule,
    BrowserModule,
    AppRoutingModule,
    BrowserAnimationsModule,
    FlexLayoutModule,
    SharedModule,

    AngularFireModule.initializeApp(environment.firebase), // Main Angular fire module
    AngularFirestoreModule
  ],
  providers: [],
  bootstrap: [AppComponent]
})
export class AppModule { }

ModuleWithProviders Migration Angular.io documentation

【问题讨论】:

  • > 项目信息 ``` "dependencies": { "@angular/animations": "~10.0.6", "@angular/cdk": "^10.1.2", "@angular /common”:“~10.0.6”,“@angular/compiler”:“~10.0.6”,“@angular/core”:“~10.0.6”,“@angular/fire”:“^6.0. 2”、“@angular/forms”:“~10.0.6”、“@angular/platform-b​​rowser”:“~10.0.6”、“@angular/platform-b​​rowser-dynamic”:“~10.0.6” ,“@angular/router”:“~10.0.6”,“firebase”:“^7.18.0”,“ngx-quicklink”:“^0.2.3”,“rxjs”:“~6.5.5”, “tslib”:“^2.0.0”,“zone.js”:“~0.10.3”}}```
  • @MariaK。上面的线程也是相同的错误代码,但没有帮助。
  • 它还包含一个讨论第 3 方集成的链接
  • @MariaK。谢谢,从您提供的线程中找到了解决方法。

标签: angular typescript firebase google-cloud-firestore angular10


【解决方案1】:

我有最新版本的 angular 并且遇到了同样的问题,只是添加了这一行:

 "skipLibCheck": true;

tconfig.app.json

    {
  "extends": "./tsconfig.json",
  "compilerOptions": {
    "outDir": "./out-tsc/app",
    "types": [],
    "skipLibCheck": true
  },
  "files": ["src/main.ts", "src/polyfills.ts"],
  "include": ["src/**/*.d.ts"]
}

【讨论】:

    【解决方案2】:

    这是 firestore 库中的错误。刚刚修好了:

    https://github.com/angular/angularfire/commit/93912bc3e9e41d48628a8671c766b0c2e8b65dc8

    尝试将您的依赖项更新到最新版本。这应该可以解决问题。

    【讨论】:

    • 是的,我正在使用最新版本的 firebase(firestore)
    • static enablePersistence(persistenceSettings?: PersistenceSettings): ModuleWithProviders&lt;AngularFirestoreModule&gt; 存在于我的本地版本的 **firestore.module.ts **
    • 关于添加 "skipLibCheck": true to tsconfig.app.json 解决了这个问题,但这样做是否正确?
    • 现在我已经评论了"skipLibCheck": true 并且它有效。
    • @RamitDour 这不是一个好主意。问题是他们在他们的 module.ts 文件中修复了这个问题,但是你的 module.d.ts 中仍然存在错误,这会产生错误。您设置的标志告诉编译器忘记检查项目中的这些文件。如果你这样做,你会失去一些类型安全性。
    【解决方案3】:

    GitHub issue 的解决方法

    工作:更新 tsconfig.app.json

    /* To learn more about this file see: https://angular.io/config/tsconfig. */
    {
      "extends": "./tsconfig.base.json",
      "compilerOptions": {
        "outDir": "./out-tsc/app",
        "types": [],
        "skipLibCheck": true
      },
      "files": [
        "src/main.ts",
        "src/polyfills.ts"
      ],
      "include": [
        "src/**/*.d.ts"
      ]
    }
    
    

    追加“skipLibCheck”:真

    【讨论】:

      【解决方案4】:

      正如另一个答案中指出的,这个问题已经得到修复:https://github.com/angular/angularfire/commit/93912bc3e9e41d48628a8671c766b0c2e8b65dc8

      但它不包含在您正在使用的最新stable 版本的@angular/fire(6.0.2 版,6 月下旬发布)中。但是,有一个可用的修复版本,它不是稳定版本,而是已修复。如果您将 @angular/fire 的版本更改为 6.0.3-canary.93912bc,它将适用于最新的 Angular 10 版本。

      【讨论】:

        猜你喜欢
        • 2017-02-08
        • 2020-10-26
        • 2023-03-14
        • 2023-03-06
        • 2020-11-19
        • 2021-04-19
        • 2022-08-04
        • 1970-01-01
        • 2020-11-14
        相关资源
        最近更新 更多