mirror of
https://github.com/gosticks/DefinitelyTyped.git
synced 2026-11-29 09:41:45 +00:00
add HOC props inference to v4 of react-i18next
This commit is contained in:
Vendored
+2
-1
@@ -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
@@ -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">;
|
||||
|
||||
Reference in New Issue
Block a user