ModuleWithProviders<T> requires 1 type argument(s) - angular-autofocus-fix

[亡魂溺海] 提交于 2021-01-27 12:50:42

问题


After installed angular-autofocus-fix

imported the AutofocusModule

When i run the angular projects its shows below error:

ERROR in node_modules/angular-autofocus-fix/index.d.ts:4:23 - error TS2314: Generic type 'ModuleWithProviders<T>' requires 1 type argument(s).
static forRoot(): ModuleWithProviders

When i check in that node_mudule

I am using angular 10 in my project.


回答1:


it seems it is not updated for Angular 10, ModuleWithProviders can no longer be used witthout generic (https://angular.io/guide/updating-to-version-10#new-removals-of-deprecated-apis)

there is an issue on the repo about it: https://github.com/korniychuk/angular-autofocus-fix/issues/14




回答2:


By adding this below given code snippet in app.module.ts fixed the issue

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

In my case, this problem happened when I upgraded ng-bootstrap version in angular-10.



来源:https://stackoverflow.com/questions/63078349/modulewithproviderst-requires-1-type-arguments-angular-autofocus-fix

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!