Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
FieldMarshallVague opened this issue Jul 3, 2017 · 9 comments

Comments

@FieldMarshallVague
Copy link

FieldMarshallVague commented Jul 3, 2017

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
Copy link

+1

2 similar comments
@EvanBurbidge
Copy link

+1

@amitrke
Copy link

amitrke commented Aug 8, 2017

+1

@shlomiassaf
Copy link
Owner

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
Copy link

entith commented Oct 12, 2017

@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
Copy link

lanovoy commented Jan 8, 2018

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

@ironicnet
Copy link

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

@hectorolan
Copy link

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
Copy link

image

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

10 participants