From f463493dcc363c524db9219d87d43ab09b86d4e0 Mon Sep 17 00:00:00 2001 From: streamich Date: Fri, 22 Nov 2019 22:48:48 +0100 Subject: [PATCH] =?UTF-8?q?fix:=20=F0=9F=90=9B=20improve=20TypeScript=20ty?= =?UTF-8?q?pings=20of=20withT()=20HOC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/createTranslations.ts | 4 ++-- src/types.ts | 9 +++++++-- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/src/createTranslations.ts b/src/createTranslations.ts index d1c2b66..7ab9db4 100644 --- a/src/createTranslations.ts +++ b/src/createTranslations.ts @@ -142,12 +142,12 @@ export const createTranslations = (ns: string = 'main'): Result => { return [state.createT ? state.createT(nss) : defaultT, state]; }; - const withT: WithT = (Comp: T, nss: string | string[] = ns) => { + const withT: WithT = (Comp, nss = ns) => { if (!Array.isArray(nss)) nss = [nss]; return (props => { const [t, T] = useT(nss as string[]); return React.createElement(Comp, {...(props as any), t, T}); - }) as T; + }); }; const Trans: React.FC = (props) => { diff --git a/src/types.ts b/src/types.ts index 292b751..273d559 100644 --- a/src/types.ts +++ b/src/types.ts @@ -49,8 +49,13 @@ export interface TransProps { // React hook. export type UseT = (namespaces?: string[]) => [TranslatorFn, ProviderState]; -// Higler order component. -export type WithT = (Comp: React.SFC, ns?: string | string[]) => React.SFC; +export interface WithTProps { + t: TranslatorFn; + T: ProviderState; +} + +// Higher order component. +export type WithT =

(Comp: React.ComponentType

, ns?: string | string[]) => React.FC>; export interface Result { Provider: React.ComponentClass;