从 Angular 版本 8 升级到 10 后。
运行 - ng serve 命令给我错误 -
node_modules/ngx-tree-select/src/module.d.ts:11:56 中的错误 - 错误 TS2314:通用类型“ModuleWithProviders”需要 1 个类型参数。
11 static forRoot(options: TreeSelectDefaultOptions): ModuleWithProviders; ~~~~~~~~~~~~~~~~~~~
这是我的文件 - front/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
Run Code Online (Sandbox Code Playgroud)
请查看错误图像。
cka*_*lla 34
@user9882419 有我认为最好的方法。这是一个例子来说明他在说什么
export class AppSharedModule {
static forRoot(): ModuleWithProviders<AppSharedModule> {
return {
ngModule: AppSharedModule
};
}
}
Run Code Online (Sandbox Code Playgroud)
Dmi*_*try 21
要跳过此类型错误,只需添加代码:
declare module "@angular/core" {
interface ModuleWithProviders<T = any> {
ngModule: Type<T>;
providers?: Provider[];
}
}
Run Code Online (Sandbox Code Playgroud)
注意:这将修复类型检查并允许继续 - 如果您发现其他 lib 与 Angular10 不兼容 - 您需要询问 lib upgrade 或找到另一个。
小智 10
在我的 Angular 10.1.3 版本中解决相同错误的方法是将 export 的参数更改为 .
有错误:
export const appRoutingProviders: any[] = [];
export const routing: ModuleWithProviders = RouterModule.forRoot(appRoutes);
Run Code Online (Sandbox Code Playgroud)
更改后:
export const appRoutingProviders: any[] = [];
export const routing: ModuleWithProviders<any> = RouterModule.forRoot(appRoutes);
Run Code Online (Sandbox Code Playgroud)
将此代码添加到您的 tsconfig.app.json
"skipLibCheck": true,
归档时间: |
|
查看次数: |
43822 次 |
最近记录: |