You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Type inference for advanced linkedSignal signature #60423
Which @angular/* package(s) are the source of the bug?
core
Is this a regression?
No
Description
The signature of linkedSignal that takes an object with source and computation properties does not allow for proper type inference, given the cyclic nature of the previous argument of the computation. Even though previous.value uses NoInfer to block TypeScript from picking up inferences from this position, TypeScript is still unable to infer type arguments if they are omitted:
We've attempted to find alternative declarations for linkedSignal, but none of them behaved entirely as we'd want. Therefore, #60857 documents the current requirement that type arguments have to be specified when using the previous argument.
Mentioning two approaches here that didn't quite work out:
1. Introduce an additional type argument to deprioritize the previous type
I'm not aware of that limitation—interestingly, Jetbrains' engine (IntelliJ and WebStorm etc.) doesn't have that problem—and there is nothing to be done about that. There's a few TS issues that appear related.
I think microsoft/TypeScript#60964 is available in typescript 5.8.3.
Might make sense to mention that. With the fix you can declare the computation return type only and avoid specifying generic arguments altogether thus source can be inferred.
Activity
Harpush commentedon Mar 17, 2025
@JoostK See discussion microsoft/TypeScript#60922
And also PR for partial fix
microsoft/TypeScript#60964
docs: document that `linkedSignal` with `previous` should include typ…
test(core): type tests for `linkedSignal`
JoostK commentedon Apr 13, 2025
We've attempted to find alternative declarations for
linkedSignal, but none of them behaved entirely as we'd want. Therefore, #60857 documents the current requirement that type arguments have to be specified when using thepreviousargument.Mentioning two approaches here that didn't quite work out:
1. Introduce an additional type argument to deprioritize the
previoustypeThis has the downside of exposing an outer type argument and isn't quite accurate in the sense that
Pcould incorrectly be a subtype ofD.2. Make the
computationcallback genericThis degree of freedom does allow for type inference in some cases, but the
Ptype isn't always inferred as desired:TypeScript playground
Notice how the
Pgeneric type argument has not been locked in to correspond withD.Harpush commentedon Apr 13, 2025
@JoostK is there a way to fix the missing intelisense for the object overload? Currently for me at least it doesn't suggest source and computation
JoostK commentedon Apr 13, 2025
I'm not aware of that limitation—interestingly, Jetbrains' engine (IntelliJ and WebStorm etc.) doesn't have that problem—and there is nothing to be done about that. There's a few TS issues that appear related.
Harpush commentedon Apr 14, 2025
I think microsoft/TypeScript#60964 is available in typescript 5.8.3.
Might make sense to mention that. With the fix you can declare the computation return type only and avoid specifying generic arguments altogether thus source can be inferred.
docs: document that `linkedSignal` with `previous` should include typ…
test(core): type tests for `linkedSignal` (#60857)
test(core): type tests for `linkedSignal` (#60857)
docs: document that `linkedSignal` with `previous` should include typ…
angular-automatic-lock-bot commentedon May 15, 2025
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.