Skip to content

QueryList's filter method doesn't support type guards #38446

@lazarljubenovic

Description

@lazarljubenovic

🐞 bug report

Affected Package

The issue is caused by package @angular/core.

Is this a regression?

No, it has never worked properly.

Description

Using a type guard as the argument for the QueryList#filter method doesn't narrow the type of the resulting array as expected. It's expected because it works when using Array#filter, which the documentation tells me to see.

🔬 Minimal Reproduction

https://stackblitz.com/edit/angular-ivy-maecij?file=src%2Fapp%2Fapp.component.ts

See line 24, and compare with 26-29.

🔥 Exception or Error

Property 'hello' does not exist on type 'HelloComponent | ByeComponent'.
  Property 'hello' does not exist on type 'ByeComponent'.

🌍 Your Environment

Angular Version: all


The fix is trivial and can be seen here:

https://github.com/microsoft/TypeScript/blob/610fa28de55d37b0e46fa1cf6394da117d29be9d/src/lib/es5.d.ts#L1151-L1162

Metadata

Metadata

Assignees

No one assigned

    Labels

    P4A relatively minor issue that is not relevant to core functionsarea: coreIssues related to the framework runtimecore: queriescross-cutting: typesfeatureIssue that requests a new featurefeature: under considerationFeature request for which voting has completed and the request is now under considerationfreq2: medium

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions