Skip to content

Commit 7459a36

Browse files
authored
feat: use const type parameters for useTranslation() (#1842)
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
1 parent 1d6fef3 commit 7459a36

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

index.d.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -97,8 +97,8 @@ export type FallbackNs<Ns> = Ns extends undefined
9797
: _DefaultNamespace;
9898

9999
export function useTranslation<
100-
Ns extends FlatNamespace | $Tuple<FlatNamespace> | undefined = undefined,
101-
KPrefix extends KeyPrefix<FallbackNs<Ns>> = undefined,
100+
const Ns extends FlatNamespace | $Tuple<FlatNamespace> | undefined = undefined,
101+
const KPrefix extends KeyPrefix<FallbackNs<Ns>> = undefined,
102102
>(
103103
ns?: Ns,
104104
options?: UseTranslationOptions<KPrefix>,

package.json

+8
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,14 @@
6767
"@babel/runtime": "^7.25.0",
6868
"html-parse-stringify": "^3.0.1"
6969
},
70+
"peerDependencies": {
71+
"typescript": "^5"
72+
},
73+
"peerDependenciesMeta": {
74+
"typescript": {
75+
"optional": true
76+
}
77+
},
7078
"devDependencies": {
7179
"@babel/cli": "^7.24.8",
7280
"@babel/core": "^7.25.2",

0 commit comments

Comments
 (0)