Skip to content

Commit 36e6936

Browse files
authored
Merge pull request #682 from panjiesw/fix/hooks-typings
hooks variant Trans props and useTranslation typings
2 parents 71fdd5b + 5788ab9 commit 36e6936

File tree

1 file changed

+36
-30
lines changed

1 file changed

+36
-30
lines changed

hooks.d.ts

Lines changed: 36 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,32 @@
1-
import i18next from 'i18next'
2-
import * as React from 'react'
3-
import { Namespace, ReactI18NextOptions, TransProps } from './src/index'
1+
import i18next from 'i18next';
2+
import * as React from 'react';
3+
import { Namespace, ReactI18NextOptions, TransProps } from './src/index';
44

55
interface HooksTransProps extends TransProps {
6-
children: React.ReactElement<any>[]
7-
tOptions: {}
8-
ns: Namespace
6+
children: React.ReactElement<any>[];
7+
tOptions?: {};
8+
ns?: Namespace;
99
}
10-
export function setDefaults(options: ReactI18NextOptions): void
11-
export function getDefaults(): ReactI18NextOptions
12-
export function addUsedNamespaces(namespaces: Namespace[]): void
13-
export function getUsedNamespaces(): string[]
14-
export function setI18n(instance: i18next.i18n): void
15-
export function getI18n(): i18next.i18n
16-
export const initReactI18next: {
17-
type: string
18-
init(instance: i18next.i18n): void
10+
interface UseTranslationOptions {
11+
i18n?: i18next.i18n;
1912
}
20-
export function composeInitialProps(ForComponent: any): (ctx: unknown) => Promise<any>
13+
export function setDefaults(options: ReactI18NextOptions): void;
14+
export function getDefaults(): ReactI18NextOptions;
15+
export function addUsedNamespaces(namespaces: Namespace[]): void;
16+
export function getUsedNamespaces(): string[];
17+
export function setI18n(instance: i18next.i18n): void;
18+
export function getI18n(): i18next.i18n;
19+
export const initReactI18next: {
20+
type: string;
21+
init(instance: i18next.i18n): void;
22+
};
23+
export function composeInitialProps(ForComponent: any): (ctx: unknown) => Promise<any>;
2124
export function getInitialProps(): {
2225
initialI18nStore: {
23-
[ns: string]: {}
24-
}
25-
initialLanguage: string
26-
}
26+
[ns: string]: {};
27+
};
28+
initialLanguage: string;
29+
};
2730
export function Trans({
2831
i18nKey,
2932
count,
@@ -37,10 +40,13 @@ export function Trans({
3740
tOptions,
3841
ns,
3942
...additionalProps
40-
}: HooksTransProps): any
43+
}: HooksTransProps): any;
4144

42-
export function useSSR(initialI18nStore: any, initialLanguage: any): void
43-
export function useTranslation(ns?: Namespace): [i18next.TranslationFunction, i18next.i18n | {}]
45+
export function useSSR(initialI18nStore: any, initialLanguage: any): void;
46+
export function useTranslation(
47+
ns?: Namespace,
48+
options?: UseTranslationOptions,
49+
): [i18next.TranslationFunction, i18next.i18n | {}];
4450

4551
export function withSSR(): (
4652
WrappedComponent: React.ComponentClass<{}, any>,
@@ -51,13 +57,13 @@ export function withSSR(): (
5157
initialLanguage,
5258
...rest
5359
}: {
54-
[x: string]: any
55-
initialI18nStore: any
56-
initialLanguage: any
60+
[x: string]: any;
61+
initialI18nStore: any;
62+
initialLanguage: any;
5763
},
58-
): React.ComponentElement<{}, React.Component<{}, any, any>>
59-
getInitialProps: (ctx: unknown) => Promise<any>
60-
}
64+
): React.ComponentElement<{}, React.Component<{}, any, any>>;
65+
getInitialProps: (ctx: unknown) => Promise<any>;
66+
};
6167
export function withTranslation(
6268
ns?: Namespace,
63-
): (WrappedComponent: React.ComponentClass<any>) => (props: any) => any
69+
): (WrappedComponent: React.ComponentClass<any>) => (props: any) => any;

0 commit comments

Comments
 (0)