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
Which Transloco package(s) will this feature affect?
Transloco, Locale
Is your feature request related to a problem? Please describe
Only the transloco pipe allows to pass undefined or null as input values in strict mode. Other pipes like the date pipe or decimal pipe cannot be used with these values. Additionally, the transloco pipe does not provide the types returned by the TranslocoMissingHandler, so returning undefined there is also a problem in strict mode.
Describe the solution you'd like
I think each pipe should have multiple overloads that consider null and undefined:
The transloco pipe should probably provide similar overloads. But I'm not sure about the return value for that pipe, because the TranslocoMissingHandler can return any, which probably needs to be restricted before providing better return types for that pipe. That would be a breaking change.
I would also return the unchanged input value if it was null or undefined. This would not print anything if used in a template, but would allow to use the correct typescript features to check for these input values based on the result and without introducing a variable (for example if the input is the output of another pipe):
// pipe returning empty string:{{(value|somePipe|translocoDecimal)||'N/A'}}// pipe returning null or undefined:{{(value|somePipe|translocoDecimal)??'N/A'}}
Describe alternatives you've considered
I have looked at how the Angular team provided their pipes, like for example the date pipe or the decimal pipe which is one reason for this ticket.
I also saw that they only provide null as return value, because they could not add undefined later on as described here, so I don't think transloco should follow that example for the return values.
Is there an existing issue for this?
Which Transloco package(s) will this feature affect?
Transloco, Locale
Is your feature request related to a problem? Please describe
Only the transloco pipe allows to pass
undefined
ornull
as input values in strict mode. Other pipes like the date pipe or decimal pipe cannot be used with these values. Additionally, the transloco pipe does not provide the types returned by theTranslocoMissingHandler
, so returningundefined
there is also a problem in strict mode.Describe the solution you'd like
I think each pipe should have multiple overloads that consider
null
andundefined
:The transloco pipe should probably provide similar overloads. But I'm not sure about the return value for that pipe, because the
TranslocoMissingHandler
can returnany
, which probably needs to be restricted before providing better return types for that pipe. That would be a breaking change.I would also return the unchanged input value if it was
null
orundefined
. This would not print anything if used in a template, but would allow to use the correct typescript features to check for these input values based on the result and without introducing a variable (for example if the input is the output of another pipe):Describe alternatives you've considered
I have looked at how the Angular team provided their pipes, like for example the date pipe or the decimal pipe which is one reason for this ticket.
I also saw that they only provide
null
as return value, because they could not addundefined
later on as described here, so I don't think transloco should follow that example for the return values.Additional context
Related to #311 and #488
I would like to make a pull request for this feature
Yes 🚀
The text was updated successfully, but these errors were encountered: