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
signal inputs seem to not work with numberAttribute (generic is needed, or needs inference) #53969
The reason is that a transform introduces a divergence in the signal's type: it accepts unknown value whereas it contains number value.
I am not sure if this can be improved upon, as TypeScript currently requires all generic types to be set instead of inferring some of them (microsoft/TypeScript#54047)
Reacted by Paul Gschwendtner, Ilir Beqiri, Lars Rye Jeppesen and Matti Järvinen
Also, in this particular case, you can opt not to specify any type arguments at all. In that case everything is fully inferred. It's only the partial inference that doesn't work.
Still, the WriteT being the first type parameter may be undesirable if partial type inference ever becomes a thing. <- This was inaccurate, thanks Paul!
Reacted by Pawel Kozlowski, Ilir Beqiri and Matti Järvinen
Thanks Joost for capturing all of this. We did consider this aspect and talked about it a couple of times. We don't see a good way around this, without other more impactful trade-offs. One correction, the type needs to be:
The first type parameter is actually the ReadT (what you as the author of the directive are dealing with), while the second parameter is the WriteT (i.e. what values can be bound to the input, and the transform converts to ReadT).
We are good, if TS supports partial type inference, the following will work as well. Right now, either need to be explicit, or fully rely on inference (which is safe here):
// will works when TS supports partial type inferencedelay=input<number>(300,{transform: numberAttribute});// works right nowdelay=input<number,unknown>(300,{transform: numberAttribute});delay=input(300,{transform: numberAttribute});
Reacted by Matti Järvinen, Pawel Kozlowski, Justin, Alix Royere, Michael Small and Omer Gronich
changed the title [-]signal inputs can't use `numberAttribute`[/-][+]signal inputs seem to not work with `numberAttribute` (generic is needed, or needs inference)[/+]on Jan 19, 2024
Activity
JoostK commentedon Jan 18, 2024
This is a bit of a gotcha, it currently needs to be
The reason is that a transform introduces a divergence in the signal's type: it accepts
unknownvalue whereas it containsnumbervalue.I am not sure if this can be improved upon, as TypeScript currently requires all generic types to be set instead of inferring some of them (microsoft/TypeScript#54047)
JoostK commentedon Jan 18, 2024
Also, in this particular case, you can opt not to specify any type arguments at all. In that case everything is fully inferred. It's only the partial inference that doesn't work.
Still, the<- This was inaccurate, thanks Paul!WriteTbeing the first type parameter may be undesirable if partial type inference ever becomes a thing.devversion commentedon Jan 18, 2024
Thanks Joost for capturing all of this. We did consider this aspect and talked about it a couple of times. We don't see a good way around this, without other more impactful trade-offs. One correction, the type needs to be:
The first type parameter is actually the
ReadT(what you as the author of the directive are dealing with), while the second parameter is theWriteT(i.e. what values can be bound to the input, and the transform converts toReadT).We are good, if TS supports partial type inference, the following will work as well. Right now, either need to be explicit, or fully rely on inference (which is safe here):
[-]signal inputs can't use `numberAttribute`[/-][+]signal inputs seem to not work with `numberAttribute` (generic is needed, or needs inference)[/+]pkozlowski-opensource commentedon Sep 11, 2024
I'm going to mark this issue as blocked since the final solution should come from microsoft/TypeScript#54047
Also developers can relatively easily deal with this situation as pointed out by #53969 (comment)
alixroyere commentedon Oct 16, 2024
Same issue with
booleanAttribute(for search reference)angular-automatic-lock-bot commentedon Jun 1, 2026
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.