Skip to content

@for with async - Object is possible null #51993

Closed

Description

@alexander-kastil

Which @angular/* package(s) are the source of the bug?

compiler

Is this a regression?

Yes

Description

I tried using the new control flow with the async pipe and got the err that the Object is possible 'null'. Voucher$ is a simple array in combination with of(arr)

    @for (v of vouchers$ | async; track v) {
      <tr>
        <td>{{ v.ID }}</td>          
      </tr>
    }

Please provide a link to a minimal reproduction of the bug

No response

Please provide the exception or error you saw

[ERROR] NG1: Object is possibly 'null'. [plugin angular-compiler]

Please provide the environment you discovered this bug in (run ng version)

_                      _                 ____ _     ___
    / \   _ __   __ _ _   _| | __ _ _ __     / ___| |   |_ _|
   / △ \ | '_ \ / _` | | | | |/ _` | '__|   | |   | |    | |
  / ___ \| | | | (_| | |_| | | (_| | |      | |___| |___ | |
 /_/   \_\_| |_|\__, |\__,_|_|\__,_|_|       \____|_____|___|
                |___/


Angular CLI: 17.0.0-next.6
Node: 18.17.1
Package Manager: npm 9.6.7
OS: win32 x64

Angular: 17.0.0-next.6
... animations, cli, common, compiler, compiler-cli, core, forms
... platform-browser, platform-browser-dynamic, router

Package                         Version
---------------------------------------------------------
@angular-devkit/architect       0.1700.0-next.6
@angular-devkit/build-angular   17.0.0-next.6
@angular-devkit/core            17.0.0-next.6
@angular-devkit/schematics      17.0.0-next.6
@angular/cdk                    17.0.0-next.5
@angular/fire                   7.6.1
@angular/material               17.0.0-next.5
@schematics/angular             17.0.0-next.6
rxjs                            7.8.1
typescript                      5.2.2
zone.js                         0.14.0

Anything else?

No response

Activity

  1. JeanMeche commented on Oct 3, 2023

    @JeanMeche
    Member

    AsyncPipe returns T|null so this kind of expected,

    transform<T>(obj: Observable<T>|Subscribable<T>|Promise<T>): T|null;
    transform<T>(obj: null|undefined): null;
    transform<T>(obj: Observable<T>|Subscribable<T>|Promise<T>|null|undefined): T|null;
    transform<T>(obj: Observable<T>|Subscribable<T>|Promise<T>|null|undefined): T|null {

    But ngFor was accepting null as input,

    set ngForOf(ngForOf: U&NgIterable<T>|undefined|null) {
    this._ngForOf = ngForOf;
    this._ngForOfDirty = true;
    }

    I don't know if that's intentional or not (there are no tests convering that)

  2. added
    area: core
    core: control flow
    on Oct 3, 2023
  3. modified the milestone: needsTriage on Oct 3, 2023
  4. crisbeto commented on Oct 3, 2023

    @crisbeto
    Member

    I chatted with @pkozlowski-opensource about this. We should support null/undefined in the expression since the runtime accounts for it already.

  5. angular-automatic-lock-bot commented on Nov 4, 2023

    @angular-automatic-lock-bot

    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.

  6. locked and limited conversation to collaborators on Nov 4, 2023
  7. added a commit that references this issue on Jan 23, 2024
    e1f2536
  8. added a commit that references this issue on Jan 26, 2024
    0eae992
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

area: corebugcore: control flowstate: has PR

Type

No type

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions