diff --git a/react-intl/index.d.ts b/react-intl/index.d.ts index ed0b639f92..e1ed69c152 100644 --- a/react-intl/index.d.ts +++ b/react-intl/index.d.ts @@ -1,6 +1,6 @@ // Type definitions for react-intl 2.2.1 // Project: http://formatjs.io/react/ -// Definitions by: Bruno Grieder , Christian Droulers , Fedor Nezhivoi , Till Wolff +// Definitions by: Bruno Grieder , Christian Droulers , Fedor Nezhivoi , Till Wolff // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped // TypeScript Version: 2.1 @@ -14,7 +14,8 @@ declare namespace ReactIntl { pluralRuleFunction?: (n: number, ord: boolean) => string; } - function injectIntl(component: React.ComponentClass | React.StatelessComponent): React.ComponentClass; + function injectIntl(component: React.ComponentClass | React.StatelessComponent): + React.ComponentClass & { WrappedComponent: React.ComponentClass | React.StatelessComponent }; function addLocaleData(data: Locale[] | Locale): void; @@ -227,7 +228,11 @@ declare namespace ReactIntl { defaultFormats?: Object; } } - class IntlProvider extends React.Component { } + class IntlProvider extends React.Component { + getChildContext(): { + intl: InjectedIntl; + } + } class LocaleData extends Array { } diff --git a/react-intl/react-intl-tests.tsx b/react-intl/react-intl-tests.tsx index d3477aaa11..3165b0583e 100644 --- a/react-intl/react-intl-tests.tsx +++ b/react-intl/react-intl-tests.tsx @@ -168,7 +168,7 @@ class SomeComponent extends React.Component = injectIntl(SomeComponent); +const SomeComponentWithIntl = injectIntl(SomeComponent); class TestApp extends React.Component<{}, {}> { public render(): React.ReactElement<{}> { @@ -191,6 +191,10 @@ class TestApp extends React.Component<{}, {}> { } } +const intlProvider = new IntlProvider({ locale: 'en' }, {}); +const { intl } = intlProvider.getChildContext(); +const wrappedComponent = + export default { TestApp, SomeComponent: SomeComponentWithIntl