File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -83,7 +83,13 @@ declare namespace React {
8383 */
8484 deprecatedLegacyContext ?: any ,
8585 ) => ReactNode )
86- | ( new ( props : P ) => Component < any , any > ) ;
86+ | ( new (
87+ props : P ,
88+ /**
89+ * @deprecated https://legacy.reactjs.org/docs/legacy-context.html#referencing-context-in-lifecycle-methods
90+ */
91+ deprecatedLegacyContext ?: any ,
92+ ) => Component < any , any > ) ;
8793
8894 interface RefObject < T > {
8995 readonly current : T | null ;
Original file line number Diff line number Diff line change @@ -810,6 +810,11 @@ const propsWithoutRef: React.PropsWithoutRef<UnionProps> = {
810810 return null ;
811811 } ;
812812 Wrapper = ( props , legacyContext : { foo : number } ) => null ;
813+ Wrapper = class Exact extends React . Component < ExactProps > {
814+ constructor ( props : ExactProps , legacyContext : { foo : number } ) {
815+ super ( props , legacyContext ) ;
816+ }
817+ } ;
813818
814819 React . createElement ( Wrapper , { value : 'A' } ) ;
815820 React . createElement ( Wrapper , { value : 'B' } ) ;
Original file line number Diff line number Diff line change @@ -357,6 +357,22 @@ class LegacyContext extends React.Component {
357357 }
358358}
359359
360+ class LegacyContextWithConstructor extends React . Component {
361+ static contextTypes = { foo : PropTypes . node . isRequired } ;
362+
363+ constructor ( props : { } , context : { } ) {
364+ super ( props , context ) ;
365+ }
366+
367+ render ( ) {
368+ // $ExpectType unknown
369+ this . context ;
370+ return ( this . context as any ) . foo ;
371+ }
372+ }
373+
374+ < LegacyContextWithConstructor /> ;
375+
360376class LegacyContextAnnotated extends React . Component {
361377 static contextTypes = { foo : PropTypes . node . isRequired } ;
362378 context : { foo : React . ReactNode } = { foo : { } as React . ReactNode } ;
Original file line number Diff line number Diff line change @@ -51,7 +51,13 @@ declare namespace React {
5151 */
5252 deprecatedLegacyContext ?: any ,
5353 ) => ReactElement < any , any > | null )
54- | ( new ( props : P ) => Component < any , any > ) ;
54+ | ( new (
55+ props : P ,
56+ /**
57+ * @deprecated https://legacy.reactjs.org/docs/legacy-context.html#referencing-context-in-lifecycle-methods
58+ */
59+ deprecatedLegacyContext ?: any ,
60+ ) => Component < any , any > ) ;
5561
5662 interface RefObject < T > {
5763 readonly current : T | null ;
Original file line number Diff line number Diff line change @@ -818,6 +818,11 @@ const propsWithoutRef: React.PropsWithoutRef<UnionProps> = {
818818 return null ;
819819 } ;
820820 Wrapper = ( props , legacyContext : { foo : number } ) => null ;
821+ Wrapper = class Exact extends React . Component < ExactProps > {
822+ constructor ( props : ExactProps , legacyContext : { foo : number } ) {
823+ super ( props , legacyContext ) ;
824+ }
825+ } ;
821826
822827 React . createElement ( Wrapper , { value : 'A' } ) ;
823828 React . createElement ( Wrapper , { value : 'B' } ) ;
Original file line number Diff line number Diff line change @@ -357,6 +357,22 @@ class LegacyContext extends React.Component {
357357 }
358358}
359359
360+ class LegacyContextWithConstructor extends React . Component {
361+ static contextTypes = { foo : PropTypes . node . isRequired } ;
362+
363+ constructor ( props : { } , context : { } ) {
364+ super ( props , context ) ;
365+ }
366+
367+ render ( ) {
368+ // $ExpectType unknown
369+ this . context ;
370+ return ( this . context as any ) . foo ;
371+ }
372+ }
373+
374+ < LegacyContextWithConstructor /> ;
375+
360376class LegacyContextAnnotated extends React . Component {
361377 static contextTypes = { foo : PropTypes . node . isRequired } ;
362378 context : { foo : React . ReactNode } = { foo : { } as React . ReactNode } ;
You can’t perform that action at this time.
0 commit comments