Skip to content

Commit

Permalink
Flow: fix React.Component constructor type
Browse files Browse the repository at this point in the history
Summary: If `super()` is not called with props, `this.props` will not be set correctly.

Reviewed By: SamChou19815

Differential Revision: D57121730

fbshipit-source-id: 62384bc688b45ac89f079f36657ce38c6f32cbee
  • Loading branch information
kassens authored and facebook-github-bot committed May 9, 2024
1 parent ea274c7 commit 2c5d2e2
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 8 deletions.
2 changes: 1 addition & 1 deletion lib/react.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ declare class React$Component<Props, State = void> {

// lifecycle methods

constructor(props?: Props, context?: any): void;
constructor(props: Props, context?: any): void;
render(): React$Node;
componentWillMount(): mixed;
UNSAFE_componentWillMount(): mixed;
Expand Down
10 changes: 5 additions & 5 deletions tests/react/react.exp
Original file line number Diff line number Diff line change
Expand Up @@ -2350,20 +2350,20 @@ References:

Error --------------------------------------------------------------------------------------------- useRef_hook.js:30:51

Cannot call `React.useRef` with `new Bar()` bound to `initialValue` because: [incompatible-call]
Cannot call `React.useRef` with `new Bar(...)` bound to `initialValue` because: [incompatible-call]
- Either `Bar` [1] is incompatible with `Foo` [2].
- Or `Bar` [1] is incompatible with null [3].

useRef_hook.js:30:51
30| const foo: {current: Foo | null} = React.useRef(new Bar()); // Error: Bar is incompatible with Foo in property current
^^^^^^^^^ [1]
30| const foo: {current: Foo | null} = React.useRef(new Bar({})); // Error: Bar is incompatible with Foo in property current
^^^^^^^^^^^ [1]

References:
useRef_hook.js:30:24
30| const foo: {current: Foo | null} = React.useRef(new Bar()); // Error: Bar is incompatible with Foo in property current
30| const foo: {current: Foo | null} = React.useRef(new Bar({})); // Error: Bar is incompatible with Foo in property current
^^^ [2]
useRef_hook.js:30:30
30| const foo: {current: Foo | null} = React.useRef(new Bar()); // Error: Bar is incompatible with Foo in property current
30| const foo: {current: Foo | null} = React.useRef(new Bar({})); // Error: Bar is incompatible with Foo in property current
^^^^ [3]


Expand Down
4 changes: 2 additions & 2 deletions tests/react/useRef_hook.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@ class Bar extends React.Component<{}, void> {}
}

{
const foo: {current: Foo | null} = React.useRef(new Foo()); // Ok
const foo: {current: Foo | null} = React.useRef(new Foo({})); // Ok
}

{
const foo: {current: Foo | null} = React.useRef(new Bar()); // Error: Bar is incompatible with Foo in property current
const foo: {current: Foo | null} = React.useRef(new Bar({})); // Error: Bar is incompatible with Foo in property current
}

0 comments on commit 2c5d2e2

Please sign in to comment.