UNPKG

2.05 kBTypeScriptView Raw
1import * as React from 'react';
2import { IntlShape } from '../types';
3declare global {
4 interface Window {
5 /**
6 * Set this to `true` prior to mounting to bypass using a globally-exposed context.
7 */
8 __REACT_INTL_BYPASS_GLOBAL_CONTEXT__: boolean | undefined;
9 __REACT_INTL_CONTEXT__: React.Context<IntlShape> | undefined;
10 }
11}
12export declare const Provider: React.Provider<IntlShape>;
13export declare const Context: React.Context<IntlShape>;
14export interface Opts<IntlPropName extends string = 'intl', ForwardRef extends boolean = false> {
15 intlPropName?: IntlPropName;
16 forwardRef?: ForwardRef;
17 enforceContext?: boolean;
18}
19export type WrappedComponentProps<IntlPropName extends string = 'intl'> = {
20 [k in IntlPropName]: IntlShape;
21};
22/**
23 * Utility type to help deal with the fact that `Omit` doesn't play well with unions:
24 * - https://github.com/microsoft/TypeScript/issues/31501
25 * - https://github.com/microsoft/TypeScript/issues/28339
26 *
27 * @example
28 * DistributedOmit<X | Y, K> --> Omit<X, K> | Omit<Y, K>
29 */
30export type DistributedOmit<T, K extends PropertyKey> = T extends unknown ? Omit<T, K> : never;
31export type WithIntlProps<P> = DistributedOmit<P, keyof WrappedComponentProps> & {
32 forwardedRef?: React.Ref<any>;
33};
34export default function injectIntl<IntlPropName extends string = 'intl', P extends WrappedComponentProps<IntlPropName> = WrappedComponentProps<any>>(WrappedComponent: React.ComponentType<P>, options?: Opts<IntlPropName, false>): React.FC<WithIntlProps<P>> & {
35 WrappedComponent: React.ComponentType<P>;
36};
37export default function injectIntl<IntlPropName extends string = 'intl', P extends WrappedComponentProps<IntlPropName> = WrappedComponentProps<any>, T extends React.ComponentType<P> = any>(WrappedComponent: React.ComponentType<P>, options?: Opts<IntlPropName, true>): React.ForwardRefExoticComponent<React.PropsWithoutRef<WithIntlProps<React.PropsWithChildren<P>>> & React.RefAttributes<T>> & {
38 WrappedComponent: React.ComponentType<P>;
39};