jsverse / transloco

🚀 😍 The internationalization (i18n) library for Angular
https://jsverse.github.io/transloco/
MIT License
2.01k stars 195 forks source link

feat(transloco|locale): Improve pipe type definitions for strict mode #770

Open Kaemmelot opened 3 months ago

Kaemmelot commented 3 months ago

PR Checklist

Please check if your PR fulfills the following requirements:

PR Type

What kind of change does this PR introduce?

What is the current behavior?

Currently the pipes don't provide overloads that can return null or undefined if provided in the input. The locale pipes transform these values into empty strings, which makes value | pipe ?? elseValue use cases hard. The typings are also not helpful for strict mode.

Issue Number: #755

What is the new behavior?

The pipes now return null or undefined as given in the input and provide method overloads to keep the typings intact for strict mode.

Does this PR introduce a breaking change?

These changes could potentially be breaking in some cases as the locale pipes now return null or undefined where they previously returned an empty string instead. The transloco pipe has new return types but returns the same values as previously, so I don't think that pipe has a breaking change.

Other information

The order of the overloads is important, because typescript tries to use the first matching overload. The docs can be seen for every overload if provided on the first one, so they must be on top.

shaharkazaz commented 2 months ago

@Kaemmelot Did you happen to see my comment?

Kaemmelot commented 2 months ago

@shaharkazaz I saw your comment and was about to change the commits.

Since this is the first time I wanted to rebase changes with GitHub as a tool, I tried the Sync button in my fork. That added an unwanted merge commit. Guess I'm not clicking that again and continue with Git and force push. Haven't used GitHub that much, some parts of the UI are a bit confusing I think.