From 9440fd14094e78c2db7345583a3aba9b36f0eefb Mon Sep 17 00:00:00 2001 From: Netanel Gilad Date: Tue, 28 Aug 2018 13:37:33 +0300 Subject: [PATCH] add HOC props inference to v4 of react-i18next --- types/react-i18next/v4/index.d.ts | 3 ++- types/react-i18next/v4/translate.d.ts | 12 +++++++++++- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/types/react-i18next/v4/index.d.ts b/types/react-i18next/v4/index.d.ts index 14676aba7e..758a00edef 100644 --- a/types/react-i18next/v4/index.d.ts +++ b/types/react-i18next/v4/index.d.ts @@ -1,6 +1,7 @@ // Type definitions for react-i18next 4.6 // Project: https://github.com/i18next/react-i18next // Definitions by: Giedrius Grabauskas +// Netanel Gilad // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped // TypeScript Version: 2.8 @@ -31,7 +32,7 @@ export { * interface MyComponentProps extends ReactI18next.InjectedTranslateProps {} */ export interface InjectedTranslateProps { - t?: TranslationFunction; + t: TranslationFunction; } export as namespace reactI18Next; diff --git a/types/react-i18next/v4/translate.d.ts b/types/react-i18next/v4/translate.d.ts index d41b4dc00a..ff715036c4 100644 --- a/types/react-i18next/v4/translate.d.ts +++ b/types/react-i18next/v4/translate.d.ts @@ -1,5 +1,6 @@ import * as React from "react"; import { i18n } from "i18next"; +import { InjectedTranslateProps } from "react-i18next"; export interface TranslateOptions { withRef?: boolean; @@ -11,5 +12,14 @@ export interface TranslateOptions { i18n?: i18n; } +// Diff / Omit taken from https://github.com/Microsoft/TypeScript/issues/12215#issuecomment-311923766 +type Omit = Pick; + +// Injects props and removes them from the prop requirements. +// Adds the new properties t (or whatever the translation function is called) and i18n if needed. +export type InferableComponentEnhancerWithProps = +

(component: React.ComponentClass

| React.StatelessComponent

) => + React.ComponentClass>; + // tslint:disable-next-line:ban-types -export default function translate(namespaces?: TKey[] | TKey, options?: TranslateOptions): (WrappedComponent: C) => C; +export default function translate(namespaces?: TKey[] | TKey, options?: TranslateOptions): InferableComponentEnhancerWithProps<"t">;