Search code examples
angularflatpickr

Angular 10 error TS2314: Generic type 'ModuleWithProviders<T>


I have upgraded to Angular 10 and I am getting the following error:

  ERROR in node_modules/angularx-flatpickr/flatpickr.module.d.ts:6:64 - error TS2314: Generic type 'ModuleWithProviders<T>' requires 1 type argument(s).

6     static forRoot(userDefaults?: FlatpickrDefaultsInterface): ModuleWithProviders;

Solution

  • Some Angular libraries, such as @angular/router and @ngrx/store, implement APIs that return a type called ModuleWithProviders (typically via a method named forRoot()). This type represents an NgModule along with additional providers. Angular version 9 deprecates use of ModuleWithProviders without an explicitly generic type, where the generic type refers to the type of the NgModule.

    read the full documentation here (https://next.angular.io/guide/migration-module-with-providers)

    open Flatpickr.module.d.ts

    and you can put unknown if you don't know the type

      export declare class FlatpickrModule {
       static forRoot(userDefaults?: FlatpickrDefaultsInterface): ModuleWithProviders<unknown>;
       }