forked from reactwaylabs/typed-i18next
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathreact.d.ts
23 lines (22 loc) · 1.19 KB
/
react.d.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
type ExtractObject<T> = T extends { [key: string]: infer TA } ? TA : never;
type IgnoreFirstParameter<TFunc> = TFunc extends (arg: any, ...restArgs: infer TArgs) => any ? TArgs : never;
export interface StrictTypedTranslations<
TTranslationsFun extends (...args: any[]) => any,
TTranslations extends { keys: { [key: string]: any }; keysWithNS: { [key: string]: any } }
> {
(ns?: undefined, ...args: IgnoreFirstParameter<TTranslationsFun>): Omit<ReturnType<TTranslationsFun>, "t"> & {
t: (key: ExtractObject<TTranslations["keys"]>, interpolate?: Object) => string;
};
<TNamespace extends keyof TTranslations["keys"]>(ns: TNamespace, ...args: IgnoreFirstParameter<TTranslationsFun>): Omit<
ReturnType<TTranslationsFun>,
"t"
> & {
t: (key: TTranslations["keys"][TNamespace], interpolate?: Object) => string;
};
<TNamespaces extends ArrayLike<keyof TTranslations["keys"]>>(ns: TNamespaces, ...args: IgnoreFirstParameter<TTranslationsFun>): Omit<
ReturnType<TTranslationsFun>,
"t"
> & {
t: (key: ExtractObject<Pick<TTranslations["keysWithNS"], TNamespaces[number]>>, interpolate?: Object) => string;
};
}