Skip to content

Commit

Permalink
types: fix some strang t function overloads, fixes #1882
Browse files Browse the repository at this point in the history
  • Loading branch information
adrai committed Dec 13, 2022
1 parent c0bc1a6 commit 0c9f8c9
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 5 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
@@ -1,3 +1,7 @@
## 22.4.4

- types: fix some strang t function overloads fixes [1882](https://github.com/i18next/i18next/issues/1882)

## 22.4.3

- types: t function overloads fix (open issue is still calling t with optional options argument)
Expand Down
10 changes: 5 additions & 5 deletions index.d.ts
Expand Up @@ -892,7 +892,7 @@ export interface TFunction<
key: TKeys | TKeys[],
): TFuncReturn<N, TKeys, TDefaultResult, TKPrefix>;
<
TKeys extends TFuncKey<PassedNS, TKPrefix> | TemplateStringsArray extends infer A ? A : never,
TKeys extends TFuncKey<PassedNS, TKPrefix>,
TDefaultResult extends DefaultTFuncReturn = string,
TInterpolationMap extends object = StringMap,
PassedNS extends Namespace = N extends string ? N : N extends unknown ? DefaultNamespace : N,
Expand All @@ -902,7 +902,7 @@ export interface TFunction<

// with returnDetails: true, returnObjects: true and ns prop in options
<
TKeys extends TFuncKey<Namespace, TKPrefix> | TemplateStringsArray extends infer A ? A : never,
TKeys extends TFuncKey<Namespace, TKPrefix>,
TDefaultResult extends DefaultTFuncReturnWithObject = object,
TInterpolationMap extends object = StringMap,
PassedNS extends Namespace = N extends string ? N : N extends null ? DefaultNamespace : N,
Expand All @@ -917,7 +917,7 @@ export interface TFunction<

// with returnObjects: true and ns prop in options
<
TKeys extends TFuncKey<Namespace, TKPrefix> | TemplateStringsArray extends infer A ? A : never,
TKeys extends TFuncKey<Namespace, TKPrefix>,
TDefaultResult extends DefaultTFuncReturnWithObject = object,
TInterpolationMap extends object = StringMap,
PassedNS extends Namespace = N extends string ? N : N extends null ? DefaultNamespace : N,
Expand All @@ -928,7 +928,7 @@ export interface TFunction<

// with passed ns prop in options
<
TKeys extends TFuncKey<PassedNS, TKPrefix> | TemplateStringsArray extends infer A ? A : never,
TKeys extends TFuncKey<PassedNS, TKPrefix>,
TDefaultResult extends DefaultTFuncReturn = string,
TInterpolationMap extends object = StringMap,
PassedNS extends Namespace = N extends string ? N : N extends null ? DefaultNamespace : N,
Expand Down Expand Up @@ -987,7 +987,7 @@ export interface TFunction<
TInterpolationMap extends object = StringMap,
>(
key: TKeys | TKeys[],
options?: TOptions<TInterpolationMap>,
options: TOptions<TInterpolationMap>,
): TFuncReturn<N, TKeys, TDefaultResult, TKPrefix>;

// defaultValue
Expand Down
3 changes: 3 additions & 0 deletions test/typescript/custom-types/i18next.d.ts
Expand Up @@ -8,6 +8,9 @@ declare module 'i18next' {
custom: {
foo: 'foo';
bar: 'bar';
baz: {
bing: 'boop';
};
};
alternate: {
baz: 'baz';
Expand Down
2 changes: 2 additions & 0 deletions test/typescript/custom-types/t.test.ts
Expand Up @@ -50,6 +50,8 @@ function i18nextTUsage() {
i18next.t('bar', { ns: 'alternate' });
// i18next.t('bar', {}).trim();
i18next.t('bar').trim();
i18next.t('baz.bing').trim();
i18next.t('alternate:foobar.barfoo').trim();

i18next.t('custom:bar', { defaultValue: 'some default value' });
i18next.t('custom:bar', 'some default value');
Expand Down

0 comments on commit 0c9f8c9

Please sign in to comment.