@@ -135,7 +135,7 @@ declare namespace React {
135
135
props : P ,
136
136
) => ReactNode | Promise < ReactNode > )
137
137
// constructor signature must match React.Component
138
- | ( new ( props : P ) => Component < any , any > ) ;
138
+ | ( new ( props : P , context : any ) => Component < any , any > ) ;
139
139
140
140
/**
141
141
* Created by {@link createRef}, or {@link useRef} when passed `null`.
@@ -218,7 +218,7 @@ declare namespace React {
218
218
type ElementRef <
219
219
C extends
220
220
| ForwardRefExoticComponent < any >
221
- | { new ( props : any ) : Component < any > }
221
+ | { new ( props : any , context : any ) : Component < any > }
222
222
| ( ( props : any ) => ReactNode )
223
223
| keyof JSX . IntrinsicElements ,
224
224
> = ComponentRef < C > ;
@@ -928,7 +928,7 @@ declare namespace React {
928
928
static propTypes ?: any ;
929
929
930
930
/**
931
- * If using the new style context , re-declare this in your class to be the
931
+ * If using React Context , re-declare this in your class to be the
932
932
* `React.ContextType` of your `static contextType`.
933
933
* Should be used with type annotation or static contextType.
934
934
*
@@ -947,6 +947,14 @@ declare namespace React {
947
947
948
948
// Keep in sync with constructor signature of JSXElementConstructor and ComponentClass.
949
949
constructor ( props : P ) ;
950
+ /**
951
+ * @param props
952
+ * @param context value of the parent {@link https://react.dev/reference/react/Component#context Context} specified
953
+ * in `contextType`.
954
+ */
955
+ // TODO: Ideally we'd infer the constructor signatur from `contextType`.
956
+ // Might be hard to ship without breaking existing code.
957
+ constructor ( props : P , context : any ) ;
950
958
951
959
// We MUST keep setState() as a unified signature because it allows proper checking of the method return type.
952
960
// See: https://github.com/DefinitelyTyped/DefinitelyTyped/issues/18365#issuecomment-351013257
@@ -1118,7 +1126,14 @@ declare namespace React {
1118
1126
*/
1119
1127
interface ComponentClass < P = { } , S = ComponentState > extends StaticLifecycle < P , S > {
1120
1128
// constructor signature must match React.Component
1121
- new ( props : P ) : Component < P , S > ;
1129
+ new (
1130
+ props : P ,
1131
+ /**
1132
+ * Value of the parent {@link https://react.dev/reference/react/Component#context Context} specified
1133
+ * in `contextType`.
1134
+ */
1135
+ context ?: any ,
1136
+ ) : Component < P , S > ;
1122
1137
/**
1123
1138
* Ignored by React.
1124
1139
* @deprecated Only kept in types for backwards compatibility. Will be removed in a future major release.
@@ -1158,7 +1173,7 @@ declare namespace React {
1158
1173
*/
1159
1174
type ClassType < P , T extends Component < P , ComponentState > , C extends ComponentClass < P > > =
1160
1175
& C
1161
- & ( new ( props : P ) => T ) ;
1176
+ & ( new ( props : P , context : any ) => T ) ;
1162
1177
1163
1178
//
1164
1179
// Component Specs and Lifecycle
0 commit comments