Skip to content

Commit 422bab1

Browse files
committed
fix: support typescript 7 — widen peer range and fix Trans ns inference under TS7 (#1927)
1 parent 6e18aa9 commit 422bab1

4 files changed

Lines changed: 13 additions & 4 deletions

File tree

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
## 17.0.9
2+
3+
- fix: allow TypeScript 7 in the optional `typescript` peer dependency range (`^5 || ^6 || ^7`). With `typescript@7.0.2` in a project, `npm install` failed with an `ERESOLVE` peer conflict. Fixes [#1927](https://github.com/i18next/react-i18next/issues/1927), thanks @andikapradanaarif.
4+
- fix(types): `<Trans t={t} ns="ns" …>` with a `t` from `useTranslation(['ns'])` now typechecks under TypeScript 7. TS7 intersects the `Ns` inference candidates coming from the `t` prop (`readonly ['ns']`) and the `ns` prop (`'ns'`) into an unsatisfiable `'ns' & readonly ['ns']`, where TS6 resolved them. The `ns` prop on `TransProps`, `TransSelectorProps` and `IcuTransWithoutContextProps` now also accepts a single namespace out of an array-typed `Ns` (`Ns | (Ns extends readonly (infer S extends string)[] ? S : never)`) — which matches runtime behavior and is unchanged under TS5/TS6.
5+
16
## 17.0.8
27

38
- fix(types): `<Trans i18nKey={$ => ...}>` now typechecks under `enableSelector: 'strict'`. The `Trans` component's conditional type was gated on `_EnableSelector extends true | 'optimize'`, excluding `'strict'` and falling back to the legacy string-key signature. Runtime was already correct (it calls `keyFromSelector(i18nKey)` whenever `typeof i18nKey === 'function'`); this is a type-only fix that widens the conditional to include `'strict'`. Thanks @Faithfinder ([#1921](https://github.com/i18next/react-i18next/pull/1921))

TransWithoutContext.d.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,9 @@ export type TransProps<
4242
defaults?: string;
4343
i18n?: i18n;
4444
i18nKey?: Key | Key[];
45-
ns?: Ns;
45+
// allow a single namespace from an array-typed `t` (e.g. useTranslation(['ns'])); TS7 intersects
46+
// inference candidates from `t` and `ns`, so a bare `Ns` here rejects ns="ns" when t is passed
47+
ns?: Ns | (Ns extends readonly (infer S extends string)[] ? S : never);
4648
parent?: string | React.ComponentType<any> | null; // used in React.createElement if not null
4749
tOptions?: TOpt;
4850
values?: InterpolationMap<Ret>;
@@ -82,7 +84,8 @@ export interface TransSelectorProps<
8284
defaults?: string | Key;
8385
i18n?: i18n;
8486
i18nKey?: Key | readonly Key[];
85-
ns?: Ns;
87+
// see TransProps.ns: keep single-namespace values assignable when `t` fixes Ns to an array
88+
ns?: Ns | (Ns extends readonly (infer S extends string)[] ? S : never);
8689
parent?: string | React.ComponentType<any> | null; // used in React.createElement if not null
8790
tOptions?: TOpt;
8891
values?: Key extends (...args: any[]) => infer R ? InterpolationMap<R> : {};

index.d.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,8 @@ export type IcuTransWithoutContextProps<
6262
/** Declaration tree describing React components and their props */
6363
content: IcuTransContentDeclaration[];
6464
/** Optional namespace(s) for the translation */
65-
ns?: Ns;
65+
// see TransProps.ns: keep single-namespace values assignable when `t` fixes Ns to an array
66+
ns?: Ns | (Ns extends readonly (infer S extends string)[] ? S : never);
6667
/** Optional values for ICU variable interpolation */
6768
values?: Record<string, any>;
6869
/** i18next instance. If not provided, uses global instance */

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@
7474
"peerDependencies": {
7575
"i18next": ">= 26.2.0",
7676
"react": ">= 16.8.0",
77-
"typescript": "^5 || ^6"
77+
"typescript": "^5 || ^6 || ^7"
7878
},
7979
"peerDependenciesMeta": {
8080
"react-dom": {

0 commit comments

Comments
 (0)