From 5788ab90e3c5343ef4670ae663399a988a48422d Mon Sep 17 00:00:00 2001 From: Panjie Setiawan Wicaksono Date: Sat, 19 Jan 2019 12:45:29 +0700 Subject: [PATCH] fix: hooks variant Trans props and useTranslation typings - Make some `Trans` props optional - Add second argument to `useTranslation` - Sync with prettier --- hooks.d.ts | 66 +++++++++++++++++++++++++++++------------------------- 1 file changed, 36 insertions(+), 30 deletions(-) diff --git a/hooks.d.ts b/hooks.d.ts index de1d4b60c..eb667b809 100644 --- a/hooks.d.ts +++ b/hooks.d.ts @@ -1,29 +1,32 @@ -import i18next from 'i18next' -import * as React from 'react' -import { Namespace, ReactI18NextOptions, TransProps } from './src/index' +import i18next from 'i18next'; +import * as React from 'react'; +import { Namespace, ReactI18NextOptions, TransProps } from './src/index'; interface HooksTransProps extends TransProps { - children: React.ReactElement[] - tOptions: {} - ns: Namespace + children: React.ReactElement[]; + tOptions?: {}; + ns?: Namespace; } -export function setDefaults(options: ReactI18NextOptions): void -export function getDefaults(): ReactI18NextOptions -export function addUsedNamespaces(namespaces: Namespace[]): void -export function getUsedNamespaces(): string[] -export function setI18n(instance: i18next.i18n): void -export function getI18n(): i18next.i18n -export const initReactI18next: { - type: string - init(instance: i18next.i18n): void +interface UseTranslationOptions { + i18n?: i18next.i18n; } -export function composeInitialProps(ForComponent: any): (ctx: unknown) => Promise +export function setDefaults(options: ReactI18NextOptions): void; +export function getDefaults(): ReactI18NextOptions; +export function addUsedNamespaces(namespaces: Namespace[]): void; +export function getUsedNamespaces(): string[]; +export function setI18n(instance: i18next.i18n): void; +export function getI18n(): i18next.i18n; +export const initReactI18next: { + type: string; + init(instance: i18next.i18n): void; +}; +export function composeInitialProps(ForComponent: any): (ctx: unknown) => Promise; export function getInitialProps(): { initialI18nStore: { - [ns: string]: {} - } - initialLanguage: string -} + [ns: string]: {}; + }; + initialLanguage: string; +}; export function Trans({ i18nKey, count, @@ -37,10 +40,13 @@ export function Trans({ tOptions, ns, ...additionalProps -}: HooksTransProps): any +}: HooksTransProps): any; -export function useSSR(initialI18nStore: any, initialLanguage: any): void -export function useTranslation(ns?: Namespace): [i18next.TranslationFunction, i18next.i18n | {}] +export function useSSR(initialI18nStore: any, initialLanguage: any): void; +export function useTranslation( + ns?: Namespace, + options?: UseTranslationOptions, +): [i18next.TranslationFunction, i18next.i18n | {}]; export function withSSR(): ( WrappedComponent: React.ComponentClass<{}, any>, @@ -51,13 +57,13 @@ export function withSSR(): ( initialLanguage, ...rest }: { - [x: string]: any - initialI18nStore: any - initialLanguage: any + [x: string]: any; + initialI18nStore: any; + initialLanguage: any; }, - ): React.ComponentElement<{}, React.Component<{}, any, any>> - getInitialProps: (ctx: unknown) => Promise -} + ): React.ComponentElement<{}, React.Component<{}, any, any>>; + getInitialProps: (ctx: unknown) => Promise; +}; export function withTranslation( ns?: Namespace, -): (WrappedComponent: React.ComponentClass) => (props: any) => any +): (WrappedComponent: React.ComponentClass) => (props: any) => any;