Skip to content

Commit

Permalink
Support static property on component wrapper by the translate() HOC (#8)
Browse files Browse the repository at this point in the history
  • Loading branch information
Kaixin authored and SBoudrias committed Aug 8, 2018
1 parent 8defd4b commit 273d661
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions src/translate.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,20 @@ import hoistStatics from 'hoist-non-react-statics';
import type { I18nType } from '.';
import { I18nContext } from './I18nProvider';

declare class TranslatedComponent<OP> extends React$Component<OP> {
static WrappedComponent: Class<React$Component<OP>>;
declare class TranslatedComponent<OP, ST> extends React$Component<OP> {
static WrappedComponent: Class<React$Component<OP>> & $Shape<ST>;
static displayName: ?string;
props: OP;
state: void;
}

declare type TranslatedComponentClass<OP> = Class<TranslatedComponent<OP>>;
declare type TranslatedComponentClass<OP, ST> = Class<TranslatedComponent<OP, ST>>;

function translate<Props>(
WrappedComponent: React.ComponentType<$Supertype<{ i18n: I18nType } & Props>>
): TranslatedComponentClass<Props> {
function translate<
Props,
Com: React.ComponentType<$Supertype<{ i18n: I18nType } & Props>>,
ST: $Subtype<{ [_: $Keys<Com>]: any }>
>(WrappedComponent: Com): TranslatedComponentClass<Props, ST> & ST {
class Translate extends React.Component<Props> {
static WrappedComponent = WrappedComponent;
static displayName = `Translate(${WrappedComponent.displayName ||
Expand Down

0 comments on commit 273d661

Please sign in to comment.