add HOC props inference to v4 of react-i18next

This commit is contained in:
Netanel Gilad
2018-08-28 13:37:33 +03:00
parent 76979d06a0
commit 9440fd1409
2 changed files with 13 additions and 2 deletions
+2 -1
View File
@@ -1,6 +1,7 @@
// Type definitions for react-i18next 4.6
// Project: https://github.com/i18next/react-i18next
// Definitions by: Giedrius Grabauskas <https://github.com/GiedriusGrabauskas>
// Netanel Gilad <https://github.com/netanelgilad>
// 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;
+11 -1
View File
@@ -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<T, K extends keyof T> = Pick<T, ({ [P in keyof T]: P } & { [P in K]: never } & { [x: string]: never, [x: number]: never })[keyof T]>;
// 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<TTranslateFunctionName extends string> =
<P extends { [key: string]: any }>(component: React.ComponentClass<P> | React.StatelessComponent<P>) =>
React.ComponentClass<Omit<P, keyof InjectedTranslateProps | TTranslateFunctionName>>;
// tslint:disable-next-line:ban-types
export default function translate<TKey extends string = string>(namespaces?: TKey[] | TKey, options?: TranslateOptions): <C extends Function>(WrappedComponent: C) => C;
export default function translate<TKey extends string = string>(namespaces?: TKey[] | TKey, options?: TranslateOptions): InferableComponentEnhancerWithProps<"t">;