Skip to content

Commit

Permalink
Fix issue which was defaulting TFunctionResult for t function (i18nex…
Browse files Browse the repository at this point in the history
  • Loading branch information
pedrodurek committed Dec 9, 2020
1 parent fca2b73 commit 24b1ee4
Showing 1 changed file with 18 additions and 16 deletions.
34 changes: 18 additions & 16 deletions src/ts4.1/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,30 +84,32 @@ export type TFuncKey<N, T = Resources> = N extends (keyof T)[]
? Normalize<T[N]>
: string;

export type TFuncReturn<N, P, T = Resources> = N extends (keyof T)[]
? NormalizeMultiReturn<T, P>
export type TFuncReturn<N, TKeys, TDefaultResult, T = Resources> = [keyof Resources] extends [never]
? TDefaultResult
: N extends (keyof T)[]
? NormalizeMultiReturn<T, TKeys>
: N extends keyof T
? NormalizeReturn<T[N], P>
: TFunctionResult;
? NormalizeReturn<T[N], TKeys>
: string;

export interface TFunction<N extends Namespace = DefaultNamespace> {
<
K extends TFuncKey<N> | TemplateStringsArray,
R extends TFuncReturn<N, K>,
I extends object = StringMap
TKeys extends TFuncKey<N> | TemplateStringsArray,
TDefaultResult extends TFunctionResult = string,
TInterpolationMap extends object = StringMap
>(
key: K | K[],
options?: TOptions<I> | string,
): R;
key: TKeys | TKeys[],
options?: TOptions<TInterpolationMap> | string,
): TFuncReturn<N, TKeys, TDefaultResult>;
<
K extends TFuncKey<N> | TemplateStringsArray,
R extends TFuncReturn<N, K>,
I extends object = StringMap
TKeys extends TFuncKey<N> | TemplateStringsArray,
TDefaultResult extends TFunctionResult = string,
TInterpolationMap extends object = StringMap
>(
key: K | K[],
key: TKeys | TKeys[],
defaultValue?: string,
options?: TOptions<I> | string,
): R;
options?: TOptions<TInterpolationMap> | string,
): TFuncReturn<N, TKeys, TDefaultResult>;
}

export interface TransProps<
Expand Down

0 comments on commit 24b1ee4

Please sign in to comment.