Skip to content

guard canLoad(), incorrect return types #18751

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

Closed
1 of 15 tasks
BigPackie opened this issue Sep 10, 2020 · 3 comments · Fixed by #18756
Closed
1 of 15 tasks

guard canLoad(), incorrect return types #18751

BigPackie opened this issue Sep 10, 2020 · 3 comments · Fixed by #18756

Comments

@BigPackie
Copy link

🐞 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

can i work on a PR for it?

@alan-agius4
Copy link
Collaborator

@geromegrignon, sure!

@alan-agius4 alan-agius4 linked a pull request Sep 11, 2020 that will close this issue
3 tasks
clydin pushed 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 pushed 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)
@angular-automatic-lock-bot
Copy link

This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.

@angular-automatic-lock-bot angular-automatic-lock-bot bot locked and limited conversation to collaborators Oct 12, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants