Skip to content

Commit 18369a3

Browse files
committed
fix #1909
1 parent 5190452 commit 18369a3

3 files changed

Lines changed: 29 additions & 5 deletions

File tree

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
### 16.6.3
2+
3+
- fix(types): merge `TransSelector` overloads into a single signature so `typeof Trans` remains extendable [1909](https://github.com/i18next/react-i18next/issues/1909)
4+
15
### 16.6.2
26

37
- feat(types): `useTranslation` now accepts selector functions as `keyPrefix` with full type-safe key narrowing when `enableSelector` is enabled [2367](https://github.com/i18next/i18next/issues/2367)

TransWithoutContext.d.ts

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -85,10 +85,11 @@ export interface TransSelectorProps<
8585
}
8686

8787
export interface TransSelector {
88-
// ── Selector function ──────────────────────────────────────────────────────
8988
<
9089
Target extends ConstrainTarget<TOpt>,
91-
Key extends SelectorFn<GetSource<$NoInfer<Ns>, KPrefix>, ApplyTarget<Target, TOpt>, TOpt>,
90+
Key extends
91+
| SelectorFn<GetSource<$NoInfer<Ns>, KPrefix>, ApplyTarget<Target, TOpt>, TOpt>
92+
| SelectorKey,
9293
const Ns extends Namespace = _DefaultNamespace,
9394
KPrefix = undefined,
9495
TContext extends string | undefined = undefined,
@@ -97,9 +98,6 @@ export interface TransSelector {
9798
>(
9899
props: TransSelectorProps<Key, Ns, KPrefix, TContext, TOpt> & E,
99100
): React.ReactElement;
100-
101-
// ── Pre-computed SelectorKey ────────────────────────────────────────────────
102-
(props: TransSelectorProps<SelectorKey> & Record<string, any>): React.ReactElement;
103101
}
104102

105103
export const Trans: _EnableSelector extends true | 'optimize' ? TransSelector : TransLegacy;

test/typescript/selector-custom-types/Trans.test.tsx

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,5 +143,27 @@ describe('<Trans />', () => {
143143
const sk = keyFromSelector(($) => $.foo);
144144
<Trans i18nKey={sk} />;
145145
});
146+
147+
it('should accept an array of SelectorKey as i18nKey', () => {
148+
const sk = keyFromSelector(($) => $.foo);
149+
<Trans i18nKey={[sk]} />;
150+
});
151+
});
152+
153+
describe('typeof Trans wrapper', () => {
154+
it('should allow extending Trans with typeof', () => {
155+
const MyTrans: typeof Trans = (props) => {
156+
return <Trans {...props} />;
157+
};
158+
<MyTrans i18nKey={($) => $.foo} />;
159+
});
160+
161+
it('should allow extending Trans with typeof and SelectorKey', () => {
162+
const sk = keyFromSelector(($) => $.foo);
163+
const MyTrans: typeof Trans = (props) => {
164+
return <Trans {...props} />;
165+
};
166+
<MyTrans i18nKey={sk} />;
167+
});
146168
});
147169
});

0 commit comments

Comments
 (0)