Skip to content

fix(core): fix narrowing of Resource.hasValue()#63994

Closed
JoostK wants to merge 1 commit intoangular:mainfrom
JoostK:core/resource-has-value-narrowing
Closed

fix(core): fix narrowing of Resource.hasValue()#63994
JoostK wants to merge 1 commit intoangular:mainfrom
JoostK:core/resource-has-value-narrowing

Conversation

@JoostK
Copy link
Copy Markdown
Member

@JoostK JoostK commented Sep 22, 2025

This commit changes Resource.hasValue() and its derived types to improve narrowing of resources whose generic type either does not include undefined (i.e. when a default value has been provided) or when the generic type is unknown. This fixes the undesirable behavior where hasValue() would cause the else branch of an hasValue() conditional to have a narrowed type of never, given that the hasValue()'s type guard covers the entire type range already (meaning that the type in the else-branch cannot be inhabited in the type system, yielding the never type).

By making the hasValue() method only a type guard when the generic type includes undefined these problems are avoided.

Fixes #60766
Fixes #63545
Fixes #63982

@JoostK JoostK added area: core Issues related to the framework runtime target: patch This PR is targeted for the next patch release cross-cutting: types core: reactivity Work related to fine-grained reactivity in the core framework labels Sep 22, 2025
@ngbot ngbot bot modified the milestone: Backlog Sep 22, 2025
@JoostK JoostK force-pushed the core/resource-has-value-narrowing branch 2 times, most recently from 8d42087 to d9faa7f Compare September 22, 2025 16:43
@JoostK JoostK marked this pull request as ready for review September 22, 2025 17:56
@JoostK JoostK added the action: review The PR is still awaiting reviews from at least one requested reviewer label Sep 22, 2025
Copy link
Copy Markdown
Contributor

@thePunderWoman thePunderWoman left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

reviewed-for: fw-general, public-api

@JeanMeche JeanMeche added the action: global presubmit The PR is in need of a google3 global presubmit label Sep 22, 2025
@JoostK JoostK force-pushed the core/resource-has-value-narrowing branch from d9faa7f to 30c85d2 Compare September 22, 2025 19:02
This commit changes `Resource.hasValue()` and its derived types to improve narrowing
of resources whose generic type either does not include `undefined` (i.e. when a default
value has been provided) or when the generic type is `unknown`. This fixes the undesirable
behavior where `hasValue()` would cause the `else` branch of an `hasValue()` conditional
to have a narrowed type of `never`, given that the `hasValue()`'s type guard covers the
entire type range already (meaning that the type in the else-branch cannot be inhabited
in the type system, yielding the `never` type).

By making the `hasValue()` method only a type guard when the generic type includes `undefined`
these problems are avoided.

Fixes angular#60766
Fixes angular#63545
Fixes angular#63982
@JoostK JoostK force-pushed the core/resource-has-value-narrowing branch from 30c85d2 to 9b888f8 Compare September 22, 2025 19:13
@JeanMeche
Copy link
Copy Markdown
Member

TGP is "green"

@JeanMeche JeanMeche added action: merge The PR is ready for merge by the caretaker and removed action: review The PR is still awaiting reviews from at least one requested reviewer action: global presubmit The PR is in need of a google3 global presubmit labels Sep 23, 2025
@JeanMeche JeanMeche removed the request for review from thePunderWoman September 23, 2025 11:40
thePunderWoman pushed a commit that referenced this pull request Sep 23, 2025
This commit changes `Resource.hasValue()` and its derived types to improve narrowing
of resources whose generic type either does not include `undefined` (i.e. when a default
value has been provided) or when the generic type is `unknown`. This fixes the undesirable
behavior where `hasValue()` would cause the `else` branch of an `hasValue()` conditional
to have a narrowed type of `never`, given that the `hasValue()`'s type guard covers the
entire type range already (meaning that the type in the else-branch cannot be inhabited
in the type system, yielding the `never` type).

By making the `hasValue()` method only a type guard when the generic type includes `undefined`
these problems are avoided.

Fixes #60766
Fixes #63545
Fixes #63982

PR Close #63994
@thePunderWoman
Copy link
Copy Markdown
Contributor

This PR was merged into the repository. The changes were merged into the following branches:

@angular-automatic-lock-bot
Copy link
Copy Markdown

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 24, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

action: merge The PR is ready for merge by the caretaker area: core Issues related to the framework runtime core: reactivity Work related to fine-grained reactivity in the core framework cross-cutting: types target: patch This PR is targeted for the next patch release

Projects

None yet

3 participants