0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

【Angular】Type 'string' is not assignable to type 'LoadChildrenCallback'.ts(2322) router.d.ts(1998, 5): '

Posted at

Angularを13にアップグレードすると

Angularを11系から13系にアップグレードしました。
するとsrc/app/app-routing.module.tsでこんなエラーが大量に・・・

Type 'string' is not assignable to type 'LoadChildrenCallback'.ts(2322) router.d.ts(1998, 5): The expected type comes from property 'loadChildren' which is declared here on type 'Route'
 Error: src/app/app-routing.module.ts:9:5 - error TS2322: Type 'string' is not assignable to type 'LoadChildrenCallback'.
[ng] 9     loadChildren: './home/home.module#HomePageModule',
[ng]       ~~~~~~~~~~~~
[ng]   node_modules/@angular/router/router.d.ts:1998:5
[ng]     1998     loadChildren?: LoadChildren;
[ng]              ~~~~~~~~~~~~
[ng]     The expected type comes from property 'loadChildren' which is declared here on type 'Route'
[ng] Error: src/app/app-routing.module.ts:14:5 - error TS2322: Type 'string' is not assignable to type 'LoadChildrenCallback'.
[ng] 14     loadChildren: './my-page/my-page.module#MyPagePageModule',
[ng]        ~~~~~~~~~~~~
[ng]   node_modules/@angular/router/router.d.ts:1998:5
[ng]     1998     loadChildren?: LoadChildren;
[ng]              ~~~~~~~~~~~~
[ng]     The expected type comes from property 'loadChildren' which is declared here on type 'Route'
[ng] Error: src/app/app-routing.module.ts:16:18 - error TS2322: Type 'string' is not assignable to type 'LoadChildrenCallback'.
[ng] 16   { path: 'day', loadChildren: './day/day.module#DayPageModule' },
[ng]                     ~~~~~~~~~~~~
[ng]   node_modules/@angular/router/router.d.ts:1998:5
[ng]     1998     loadChildren?: LoadChildren;
[ng]              ~~~~~~~~~~~~
[ng]     The expected type comes from property 'loadChildren' which is declared here on type 'Route'
[ng] Error: src/app/app-routing.module.ts:17:22 - error TS2322: Type 'string' is not assignable to type 'LoadChildrenCallback'.

dynamic importの書き方が変わったようです!

app-routing.module.ts
// 古いバージョン
  {
    path: 'my-page/:id',
    loadChildren: './my-page/my-page.module#MyPagePageModule',
  },

// 新しいバージョン
 {
    path: 'my-page/:id',
    loadChildren: () => import('./my-page/my-page.module').then(m => m.MyPagePageModule),
  },

また、tsconfig.json"module": "esnext"になっているか要確認!

{
...
"compilerOptions": {
    ...
    "module": "esnext"
    ...
    }
}

参考

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?