Home > Enterprise >  How to solve ESLint typedef error for importing lazy modules into routing module Angular?
How to solve ESLint typedef error for importing lazy modules into routing module Angular?

Time:09-14

I'm importing lazy loading modules into my routing modules as it is shown in Angular tutorial. But ESLint doesn't like that I don't mention type annotation for it.

How is it possible to solve this issue whithout setting ESLint to ignore this rule?

  {
    path: 'user',
    children: [
      {
        path: ':id',
        loadChildren: () =>
          import('./user/user.module').then(
            (m) => m.UserModule,
          ),
      },
    ],
  }

enter image description here

CodePudding user response:

You can do type annotation several ways like this:

Simple, not preferred

loadChildren: () =>
  import('./user/user.module').then(
    (m: Params) => m.UserModule,
  ),

More precise:

loadChildren: () =>
      import('./user/user.module').then(
        (m: typeof import('./user/user.module')) => m.UserModule,
      ),

Even more precise:

loadChildren: () => import('./user/user.module').then(
    (m: { UserModule: Type<UserModule> }) => m.UserModule,
),
  • Related