close
The Wayback Machine - https://web.archive.org/web/20200912002431/https://github.com/angular/angular-cli/issues/18751
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

guard canLoad(), incorrect return types #18751

Closed
BigPackie opened this issue Sep 10, 2020 · 2 comments
Closed

guard canLoad(), incorrect return types #18751

BigPackie opened this issue Sep 10, 2020 · 2 comments

Comments

@BigPackie
Copy link

@BigPackie BigPackie commented Sep 10, 2020

🐞 Bug report

Command (mark with an x)

  • new
  • build
  • serve
  • test
  • e2e
  • generate
  • add
  • update
  • lint
  • xi18n
  • run
  • config
  • help
  • version
  • doc

Is this a regression?

Probably not

Description

generating a guard with canLoad() method creates it with a wrong return type.

🔬 Minimal Reproduction

ng g guard auth/test --implements CanLoad

🔥 Exception or Error





🌍 Your Environment




@angular-devkit/architect         0.1000.8
@angular-devkit/build-angular     0.1000.8
@angular-devkit/build-optimizer   0.1000.8
@angular-devkit/build-webpack     0.1000.8
@angular-devkit/core              10.0.8
@angular-devkit/schematics        10.0.8
@angular/cdk                      10.2.0
@angular/cli                      10.0.8
@angular/material                 10.2.0
@ngtools/webpack                  10.0.8
@schematics/angular               10.0.8
@schematics/update                0.1000.8
rxjs                              6.5.5
typescript                        3.9.7
webpack                           4.43.0

Anything else relevant?

The generated class:

export class TestGuard implements CanLoad {
  canLoad(
    route: Route,
    segments: UrlSegment[]): Observable<boolean> | Promise<boolean> | boolean {
    return true;
  }
}

Should be:

export class TestGuard implements CanLoad {
  canLoad(
    route: Route,
    segments: UrlSegment[]): Observable<boolean | UrlTree> | Promise<boolean | UrlTree> | boolean | UrlTree {
    return true;
  }

}

The return type is not correct, according to angular docs | UrlTree is missing

@geromegrignon
Copy link
Contributor

@geromegrignon geromegrignon commented Sep 11, 2020

can i work on a PR for it?

@alan-agius4
Copy link
Collaborator

@alan-agius4 alan-agius4 commented Sep 11, 2020

@alan-agius4 alan-agius4 linked a pull request that will close this issue Sep 11, 2020
2 of 3 tasks complete
geromegrignon added a commit to geromegrignon/angular-cli that referenced this issue Sep 11, 2020
add UrlTree to canLoad guard signature to match the documentation and the other implementations

Closes: angular#18751
clydin added a commit that referenced this issue Sep 11, 2020
add UrlTree to canLoad guard signature to match the documentation and the other implementations

Closes: #18751
clydin added a commit that referenced this issue Sep 11, 2020
add UrlTree to canLoad guard signature to match the documentation and the other implementations

Closes: #18751
(cherry picked from commit 8e05a5e)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

3 participants
You can’t perform that action at this time.