Skip to content

feat: use const type parameters for useTranslation() #1842

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

Merged
merged 1 commit into from
Apr 23, 2025

Conversation

emersion
Copy link
Contributor

@emersion emersion commented Apr 22, 2025

TypeScript 5.0 has introduced const type parameters. These indicate that a more specific type is preferred over a more general one. As a result, the resulting UseTranslationResponse will be more precise and retain the passed-in namespace and prefix. This can be used by extractors and other tooling to find out exactly which key is accessed by a translation function call.

Checklist

  • only relevant code is changed (make a diff before you submit the PR)
  • run tests npm run test
  • tests are included (N/A: there is no way to extract generic type parameters from a test)
  • commit message and code follows the Developer's Certification of Origin

@adrai adrai requested a review from marcalexiei April 22, 2025 16:50
@coveralls
Copy link

coveralls commented Apr 22, 2025

Coverage Status

coverage: 95.797%. remained the same
when pulling 2a0bd3b on emersion:use-translation-const-type-params
into 1d6fef3 on i18next:master.

emersion added a commit to OpenRailAssociation/osrd that referenced this pull request Apr 22, 2025
@adrai
Copy link
Member

adrai commented Apr 22, 2025

@marcalexiei ok for you?

Copy link
Contributor

@marcalexiei marcalexiei left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since you are introducing TypeScript 5 features consider to make it an optional dependency.
It should be the same of i18next:

https://github.com/i18next/i18next/blob/c40d0a2744582deedacf7d10e534182449992e4e/package.json#L54-L61

TypeScript 5.0 has introduced const type parameters [1]. These indicate
that a more specific type is preferred over a more general one. As
a result, the resulting UseTranslationResponse will be more precise
and retain the passed-in namespace and prefix. This can be used by
extractors and other tooling to find out exactly which key is
accessed by a translation function call.

[1]: https://www.typescriptlang.org/docs/handbook/release-notes/typescript-5-0.html#const-type-parameters
@emersion emersion force-pushed the use-translation-const-type-params branch from 9dc4de3 to 2a0bd3b Compare April 23, 2025 08:43
@emersion
Copy link
Contributor Author

Makes sense to me, done!

@adrai adrai merged commit 7459a36 into i18next:master Apr 23, 2025
8 checks passed
@emersion emersion deleted the use-translation-const-type-params branch April 23, 2025 08:54
@emersion
Copy link
Contributor Author

Thanks for the speedy review!

@adrai
Copy link
Member

adrai commented Apr 23, 2025

thanks both of you...
included in v15.5.0

emersion added a commit to OpenRailAssociation/osrd that referenced this pull request Apr 23, 2025
emersion added a commit to OpenRailAssociation/osrd that referenced this pull request Apr 24, 2025
emersion added a commit to OpenRailAssociation/osrd that referenced this pull request Apr 24, 2025
emersion added a commit to OpenRailAssociation/osrd that referenced this pull request Apr 29, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants