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.
@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
};
}
}
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.
add this code in your tsconfig.app.json
"skipLibCheck": true,
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);
You just need to specify the type (the name of the module class) between ModuleWithProviders
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With