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

Feature(transloco|transloco-locale): Provide complete type definitions for pipes used in strict mode #755

Open
1 task done
Kaemmelot opened this issue Apr 3, 2024 · 1 comment

Comments

@Kaemmelot
Copy link

Kaemmelot commented Apr 3, 2024

Is there an existing issue for this?

  • I have searched the existing issues

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:

transform(value: TYPE): string;
transform(value: TYPE | null | undefined): string | null | undefined;
transform(value: null | undefined): null | 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.

Additional context

Related to #311 and #488

I would like to make a pull request for this feature

Yes 🚀

@shaharkazaz
Copy link
Collaborator

You are welcome to open a PR for it 👍

Kaemmelot added a commit to Kaemmelot/transloco that referenced this issue Jun 6, 2024
Kaemmelot added a commit to Kaemmelot/transloco that referenced this issue Jun 6, 2024
Keep null and undefined intact and provide overloads with null and
undefined values for all pipes.

BREAKING CHANGE: 🧨 Pipes return null or undefined instead of an empty string if the input
is null or undefined

✅ Closes: jsverse#755
Kaemmelot added a commit to Kaemmelot/transloco that referenced this issue Jul 24, 2024
Kaemmelot added a commit to Kaemmelot/transloco that referenced this issue Jul 24, 2024
Keep null and undefined intact and provide overloads with null and
undefined values for all pipes.

BREAKING CHANGE: 🧨 Pipes return null or undefined instead of an empty string if the input
is null or undefined

✅ Closes: jsverse#755
Kaemmelot added a commit to Kaemmelot/transloco that referenced this issue Jul 24, 2024
Kaemmelot added a commit to Kaemmelot/transloco that referenced this issue Jul 24, 2024
Keep null and undefined intact and provide overloads with null and
undefined values for all pipes.

BREAKING CHANGE: 🧨 Pipes return null or undefined instead of an empty string if the input
is null or undefined

✅ Closes: jsverse#755
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants