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

fix(core): QueryList first and last might be undefined #55701

Closed

Conversation

PowerKiKi
Copy link
Contributor

PR Checklist

Please check if your PR fulfills the following requirements:

PR Type

What kind of change does this PR introduce?

  • Bugfix
  • Feature
  • Code style update (formatting, local variables)
  • Refactoring (no functional changes, no api changes)
  • Build related changes
  • CI related changes
  • Documentation content changes
  • angular.io application / infrastructure changes
  • Other... Please describe:

What is the current behavior?

It is possible that a QueryList has no results at all, and thus there is no first or last result.

Issue Number: N/A

What is the new behavior?

The typing now reflects that reality.

Does this PR introduce a breaking change?

  • Yes
  • No

if you are using TypeScript strict mode, you must now check for the existence of first and last before using them.

Other information

none

@pullapprove pullapprove bot requested a review from thePunderWoman May 7, 2024 04:47
@angular-robot angular-robot bot added the detected: breaking change PR contains a commit with a breaking change label May 7, 2024
@PowerKiKi PowerKiKi force-pushed the querylist-undefined-first-last branch from 56c50e9 to 2e2f790 Compare May 7, 2024 05:01
It is possible that a QueryList has no results at all, and thus `first`
or `last` might be `undefined`. The typing now reflects that reality.

BREAKING CHANGE: if you are using TypeScript strict mode, you must now
check for the existence of `first` and `last` before using them.

BREAKING CHANGE: `QueryList.changes` emissions no longer allow access to
anything. Instead, you must respect the new typing of `QueryList<T>`.
@PowerKiKi PowerKiKi force-pushed the querylist-undefined-first-last branch from 2e2f790 to 670f231 Compare May 7, 2024 05:08
@PowerKiKi PowerKiKi marked this pull request as draft May 7, 2024 07:49
@PowerKiKi PowerKiKi marked this pull request as ready for review May 7, 2024 08:32
@JeanMeche
Copy link
Member

JeanMeche commented May 7, 2024

Hi, this change was already tried to being landed a couples of year back, cf #43604.
Since this is a breaking change, it requires a migration.

There is little value to put the effort of landing this now that we have the signal view queries.

@PowerKiKi
Copy link
Contributor Author

The CI is failing with many TypeError: Cannot read properties of null (reading 'ngModule') errors. I don't think it is related to my PR, but if it is, please help me understand what/where I should fix ?

@PowerKiKi
Copy link
Contributor Author

I was not aware of the previous attempts, including yours 😞 ...

The way I see it this API is not deprecated, so improving it would still bring value to people who use it. And the fact that it is the third attempts to fix it seems to indicate that some people care.

I'll let you reject the PR if you think this is a dead end.

@dylhunn
Copy link
Contributor

dylhunn commented May 22, 2024

Hi @PowerKiKi. While I agree that the spirit of this change is great, the problem is that we would break a ton of code that relies on first and last and assumes they will never be undefined. We'd need to run a migration to fix all the user code, including inside of Google.

I think we're going to leave it alone, since we have replacement signals-based APIs anyway.

Thank you for your effort on this though, and sorry we cannot accept it!

@dylhunn dylhunn closed this May 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
detected: breaking change PR contains a commit with a breaking change
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants