Skip to content

Commit d105351

Browse files
SamChou19815facebook-github-bot
authored andcommitted
[flow] Kill React$Component
Summary: Changelog: [errors] Referencing `React$Component` directly will now be an error. Reviewed By: jbrown215 Differential Revision: D70015939 fbshipit-source-id: 7da53dde3e84b579e1cfaf600d9f8b4c27809de4
1 parent db61e9c commit d105351

File tree

41 files changed

+1341
-1344
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+1341
-1344
lines changed

lib/react.js

Lines changed: 74 additions & 81 deletions
Original file line numberDiff line numberDiff line change
@@ -22,85 +22,6 @@ declare type React$Node =
2222
| React$Portal
2323
| Iterable<?React$Node>;
2424

25-
26-
/**
27-
* Base class of ES6 React classes, modeled as a polymorphic class whose main
28-
* type parameters are Props and State.
29-
*/
30-
declare class React$Component<Props, State = void> {
31-
// fields
32-
33-
props: Props;
34-
state: State;
35-
36-
// action methods
37-
38-
setState(
39-
partialState: ?$ReadOnly<Partial<State>> | ((State, Props) => ?$ReadOnly<Partial<State>>),
40-
callback?: () => mixed,
41-
): void;
42-
43-
forceUpdate(callback?: () => void): void;
44-
45-
// lifecycle methods
46-
47-
constructor(props: Props, context?: any): void;
48-
render(): React$Node;
49-
componentWillMount(): mixed;
50-
UNSAFE_componentWillMount(): mixed;
51-
componentDidMount(): mixed;
52-
componentWillReceiveProps(
53-
nextProps: Props,
54-
nextContext: any,
55-
): mixed;
56-
UNSAFE_componentWillReceiveProps(
57-
nextProps: Props,
58-
nextContext: any,
59-
): mixed;
60-
shouldComponentUpdate(
61-
nextProps: Props,
62-
nextState: State,
63-
nextContext: any,
64-
): boolean;
65-
componentWillUpdate(
66-
nextProps: Props,
67-
nextState: State,
68-
nextContext: any,
69-
): mixed;
70-
UNSAFE_componentWillUpdate(
71-
nextProps: Props,
72-
nextState: State,
73-
nextContext: any,
74-
): mixed;
75-
componentDidUpdate(
76-
prevProps: Props,
77-
prevState: State,
78-
prevContext: any,
79-
): mixed;
80-
componentWillUnmount(): mixed;
81-
componentDidCatch(
82-
error: Error,
83-
info: { componentStack: string, ... }
84-
): mixed;
85-
86-
// long tail of other stuff not modeled very well
87-
88-
refs: any;
89-
context: any;
90-
getChildContext(): any;
91-
static displayName?: ?string;
92-
static childContextTypes: empty;
93-
static contextTypes: empty;
94-
static propTypes: any;
95-
96-
// We don't add a type for `defaultProps` so that its type may be entirely
97-
// inferred when we diff the type for `defaultProps` with `Props`. Otherwise
98-
// the user would need to define a type (which would be redundant) to override
99-
// the type we provide here in the base class.
100-
//
101-
// static defaultProps: $Shape<Props>;
102-
}
103-
10425
declare type React$AbstractComponentStatics = {
10526
displayName?: ?string,
10627
// This is only on function components, but trying to access name when
@@ -327,7 +248,7 @@ declare module react {
327248
*
328249
* @see https://react.dev/reference/react/Component
329250
*/
330-
declare export const Component: typeof React$Component;
251+
declare export const Component: typeof React.Component;
331252

332253
/**
333254
* `PureComponent` is similar to `Component`, but it skip re-renders with same props.
@@ -711,7 +632,79 @@ declare module react {
711632
*
712633
* @see https://react.dev/reference/react/Component
713634
*/
714-
declare const Component: typeof React$Component;
635+
declare class Component<Props, State = void> {
636+
// fields
637+
638+
props: Props;
639+
state: State;
640+
641+
// action methods
642+
643+
setState(
644+
partialState: ?$ReadOnly<Partial<State>> | ((State, Props) => ?$ReadOnly<Partial<State>>),
645+
callback?: () => mixed,
646+
): void;
647+
648+
forceUpdate(callback?: () => void): void;
649+
650+
// lifecycle methods
651+
652+
constructor(props: Props, context?: any): void;
653+
render(): React$Node;
654+
componentWillMount(): mixed;
655+
UNSAFE_componentWillMount(): mixed;
656+
componentDidMount(): mixed;
657+
componentWillReceiveProps(
658+
nextProps: Props,
659+
nextContext: any,
660+
): mixed;
661+
UNSAFE_componentWillReceiveProps(
662+
nextProps: Props,
663+
nextContext: any,
664+
): mixed;
665+
shouldComponentUpdate(
666+
nextProps: Props,
667+
nextState: State,
668+
nextContext: any,
669+
): boolean;
670+
componentWillUpdate(
671+
nextProps: Props,
672+
nextState: State,
673+
nextContext: any,
674+
): mixed;
675+
UNSAFE_componentWillUpdate(
676+
nextProps: Props,
677+
nextState: State,
678+
nextContext: any,
679+
): mixed;
680+
componentDidUpdate(
681+
prevProps: Props,
682+
prevState: State,
683+
prevContext: any,
684+
): mixed;
685+
componentWillUnmount(): mixed;
686+
componentDidCatch(
687+
error: Error,
688+
info: { componentStack: string, ... }
689+
): mixed;
690+
691+
// long tail of other stuff not modeled very well
692+
693+
refs: any;
694+
context: any;
695+
getChildContext(): any;
696+
static displayName?: ?string;
697+
static childContextTypes: empty;
698+
static contextTypes: empty;
699+
static propTypes: any;
700+
701+
// We don't add a type for `defaultProps` so that its type may be entirely
702+
// inferred when we diff the type for `defaultProps` with `Props`. Otherwise
703+
// the user would need to define a type (which would be redundant) to override
704+
// the type we provide here in the base class.
705+
//
706+
// static defaultProps: $Shape<Props>;
707+
}
715708

716709
/**
717710
* `PureComponent` is similar to `Component`, but it skip re-renders with same props.

src/typing/__tests__/type_hint_test.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -597,7 +597,7 @@ let eval_hint_tests =
597597
"jsx_props_of_class_component"
598598
>:: mk_eval_hint_test_with_type_setup
599599
~expected:"{+bar: string, +foo: number}"
600-
"class MyComponent extends React$Component<{bar: string, foo: number}> {}; MyComponent"
600+
"import * as React from 'react'; class MyComponent extends React.Component<{bar: string, foo: number}> {}; MyComponent"
601601
[Decomp_JsxProps];
602602
"jsx_props_of_function_component"
603603
>:: mk_eval_hint_test

tests/autocomplete_from_m_to_q/autocomplete_from_m_to_q.exp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -772,7 +772,6 @@ Flags: --pretty
772772
},
773773
{"name":"Range","type":"typeof Range"},
774774
{"name":"RangeError","type":"typeof RangeError"},
775-
{"name":"React$Component","type":"typeof React$Component"},
776775
{
777776
"name":"ReadableByteStreamController",
778777
"type":"typeof ReadableByteStreamController"

tests/badly_positioned_react/badly_positioned_react.exp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ References:
1414
test.js:21:29
1515
21| const Foo1 = create(create1<{||}>(Foo));
1616
^^^^ [2]
17-
<BUILTINS>/react.js:341:38
18-
341| declare export type ComponentType<-P> = React$ComponentType<P>;
17+
<BUILTINS>/react.js:262:38
18+
262| declare export type ComponentType<-P> = React$ComponentType<P>;
1919
^ [3]
2020

2121

0 commit comments

Comments
 (0)