Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Angular error - Generic type 'ModuleWithProviders<T>' requires 1 type argument(s)

Tags:

angular

After upgrading from Angular version 8 to 10.

Running the - ng serve command gives me error -

ERROR in node_modules/ngx-tree-select/src/module.d.ts:11:56 - error TS2314: Generic type 'ModuleWithProviders' requires 1 type argument(s).

11 static forRoot(options: TreeSelectDefaultOptions): ModuleWithProviders; ~~~~~~~~~~~~~~~~~~~

This is my file - fronent/webapp/node_modules/ngx-tree-select/src/module.d.ts

import { ModuleWithProviders } from '@angular/core';
import { TreeSelectDefaultOptions } from './models/tree-select-default-options';
import * as ɵngcc0 from '@angular/core';
import * as ɵngcc1 from './components/tree-select.component';
import * as ɵngcc2 from './components/tree-select-item.component';
import * as ɵngcc3 from './directives/off-click.directive';
import * as ɵngcc4 from './pipes/item.pipe';
import * as ɵngcc5 from '@angular/common';
import * as ɵngcc6 from '@angular/forms';
export declare class NgxTreeSelectModule {
    static forRoot(options: TreeSelectDefaultOptions): ModuleWithProviders;
    static ɵmod: ɵngcc0.ɵɵNgModuleDefWithMeta<NgxTreeSelectModule, [typeof ɵngcc1.TreeSelectComponent, typeof ɵngcc2.TreeSelectItemComponent, typeof ɵngcc3.OffClickDirective, typeof ɵngcc4.ItemPipe], [typeof ɵngcc5.CommonModule, typeof ɵngcc6.FormsModule], [typeof ɵngcc1.TreeSelectComponent]>;
    static ɵinj: ɵngcc0.ɵɵInjectorDef<NgxTreeSelectModule>;
}

//# sourceMappingURL=module.d.ts.map

Kindly view the image for the error.

enter image description here

like image 309
Akanksha Mohanty Avatar asked Jul 06 '20 11:07

Akanksha Mohanty


5 Answers

@user9882419 has the best approach i believe. Here is an example to illustrate what he is saying

export class AppSharedModule {
  static forRoot(): ModuleWithProviders<AppSharedModule> {
    return {
      ngModule: AppSharedModule
    };
  }
}
like image 56
ckapilla Avatar answered Oct 17 '22 22:10

ckapilla


To skip this type error just add in you code:

declare module "@angular/core" {
    interface ModuleWithProviders<T = any> {
        ngModule: Type<T>;
        providers?: Provider[];
    }
}

Note: this will fix the type checking and allow to continue - if you will notice other lib to Angular10 inconmpatibilities - you need to ask lib upgrade or found another one.

like image 30
Dmitry Avatar answered Oct 17 '22 22:10

Dmitry


add this code in your tsconfig.app.json "skipLibCheck": true,

enter image description here

like image 16
Mafei Avatar answered Oct 17 '22 22:10

Mafei


The solve for the same error in my Angular 10.1.3 version, was change the param of export to .

With error:

export const appRoutingProviders: any[] = [];
export const routing: ModuleWithProviders = RouterModule.forRoot(appRoutes);

After change:

export const appRoutingProviders: any[] = [];
export const routing: ModuleWithProviders<any> = RouterModule.forRoot(appRoutes);
like image 13
daniel021sv Avatar answered Oct 17 '22 21:10

daniel021sv


You just need to specify the type (the name of the module class) between ModuleWithProviders

like image 7
user9882419 Avatar answered Oct 17 '22 20:10

user9882419