@@ -20,9 +20,12 @@ const {Consumer: IntlConsumer, Provider: IntlProvider} = IntlContext;
20
20
export const Provider = IntlProvider ;
21
21
export const Context = IntlContext ;
22
22
23
- export interface Opts < IntlPropName extends string = 'intl' > {
23
+ export interface Opts <
24
+ IntlPropName extends string = 'intl' ,
25
+ ForwardRef extends boolean = false
26
+ > {
24
27
intlPropName ?: IntlPropName ;
25
- forwardRef ?: boolean ;
28
+ forwardRef ?: ForwardRef ;
26
29
enforceContext ?: boolean ;
27
30
}
28
31
@@ -35,12 +38,37 @@ export type WithIntlProps<P> = Omit<P, keyof WrappedComponentProps> & {
35
38
} ;
36
39
37
40
export default function injectIntl <
38
- IntlPropName extends string = 'intl' ,
41
+ IntlPropName extends string ,
39
42
P extends WrappedComponentProps < IntlPropName > = WrappedComponentProps < any >
40
43
> (
41
44
WrappedComponent : React . ComponentType < P > ,
42
- options ?: Opts < IntlPropName >
43
- ) : React . ComponentType < WithIntlProps < P > > & {
45
+ options ?: Opts < IntlPropName , false >
46
+ ) : React . FC < WithIntlProps < P > > & {
47
+ WrappedComponent : typeof WrappedComponent ;
48
+ } ;
49
+ export default function injectIntl <
50
+ IntlPropName extends string = 'intl' ,
51
+ P extends WrappedComponentProps < IntlPropName > = WrappedComponentProps < any > ,
52
+ T extends React . ComponentType < P > = any
53
+ > (
54
+ WrappedComponent : React . ComponentType < P > ,
55
+ options ?: Opts < IntlPropName , true >
56
+ ) : React . ForwardRefExoticComponent <
57
+ React . PropsWithoutRef < WithIntlProps < P > > & React . RefAttributes < T >
58
+ > & {
59
+ WrappedComponent : typeof WrappedComponent ;
60
+ } ;
61
+ export default function injectIntl <
62
+ IntlPropName extends string = 'intl' ,
63
+ P extends WrappedComponentProps < IntlPropName > = WrappedComponentProps < any > ,
64
+ ForwardRef extends boolean = false ,
65
+ T extends React . ComponentType < P > = any
66
+ > (
67
+ WrappedComponent : React . ComponentType < P > ,
68
+ options ?: Opts < IntlPropName , ForwardRef >
69
+ ) : React . ForwardRefExoticComponent <
70
+ React . PropsWithoutRef < WithIntlProps < P > > & React . RefAttributes < T >
71
+ > & {
44
72
WrappedComponent : typeof WrappedComponent ;
45
73
} {
46
74
const { intlPropName = 'intl' , forwardRef = false , enforceContext = true } =
@@ -72,7 +100,7 @@ export default function injectIntl<
72
100
73
101
if ( forwardRef ) {
74
102
return hoistNonReactStatics (
75
- React . forwardRef ( ( props : P , ref ) => (
103
+ React . forwardRef < T , P > ( ( props : P , ref ) => (
76
104
< WithIntl { ...props } forwardedRef = { ref } />
77
105
) ) ,
78
106
WrappedComponent
0 commit comments