shlomiassaf / ng-router-loader

Webpack loader for NgModule lazy loading using the angular router
MIT License
46 stars 8 forks source link

loadChildren: ()=> './myroute/blah/blah' is not assignable to type Route #13

Open FieldMarshallVague opened 7 years ago

FieldMarshallVague commented 7 years ago

Hi there,

I'm getting the above error when I'm configuring my routes. I'm following the docs exactly as described, but the lamba expression fails the Typescript intellisense (in VS2015) and the build process does not complete.

I'm using ng-router-loader 2.1.0 and angular 4.1.2 (angular/router 4.1.2).

The specific error is this:

Type '{ path: string; loadChildren: () => string; }' is not assignable to type 'Route'.

My code is basically this: { path: 'sales', loadChildren: './sales.module#SalesModule' },

I realise this isn't likely to be ng-router-loader's problem, but that is the specific format the documentation says to use, so I'm starting here :)

Do I need to match a specific version of angular or similar?

Thanks.

kirill-onufrienko-db commented 7 years ago

+1

EvanBurbidge commented 7 years ago

+1

amitrke commented 7 years ago

+1

shlomiassaf commented 7 years ago

Hi

This is not clear to me... The loadChildren type is:

export type LoadChildren = string | LoadChildrenCallback;

Si there is no violation there...

Is it specific to VS2015? What's the TS version?

entith commented 6 years ago

@shlomiassaf According to the current Angular documentation, LoadChildrenCallback is a function that returns one of Type<any>| NgModuleFactory<any>| Promise<Type<any>>| Observable<Type<any>>, not a string.

type LoadChildrenCallback = () =>
Type<any>| NgModuleFactory<any>| Promise<Type<any>>| Observable<Type<any>>;

Assigning loadChildren a string works, but assigning it a callback function that returns a string (as per your documentation) does not work.

lanovoy commented 6 years ago

Assigning lambda will also break AoT... So just avoid it?

ironicnet commented 6 years ago

I'm having the same issue... Also, passing a valid string isn't working for me either...

hectorolan commented 6 years ago

I had the same issue, I am on Angular 5.2.1. Try to explicit declare the variable route:

import { RouterModule, Route } from '@angular/router';

then update the variable that you are using for example:

var routes: Route[] = [ { path: 'main', loadChildren: './components/main/main.module#MainModule' }, { path: '', redirectTo: 'main', pathMatch: 'full' }, { path: '**', redirectTo: 'main' } ];

dchirag005 commented 2 years ago

image

i am facing problem in loadchildren value asign. i can use angular version = 13.1.0 typescript = 4.5.2