Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[react] New useReducer signature #7420

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 15 additions & 2 deletions lib/react.js
Original file line number Diff line number Diff line change
Expand Up @@ -316,11 +316,24 @@ declare module react {
initialState: (() => S) | S,
): [S, ((S => S) | S) => void];

declare type Dispatch<A> = (A) => void;

declare export function useReducer<S, A>(
reducer: (S, A) => S,
initialState: S,
initialAction: ?A,
): [S, A => void];
): [S, Dispatch<A>];

declare export function useReducer<S, A>(
reducer: (S, A) => S,
initialState: S,
init: void,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How is this type overload different from the previous one?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Otherwise Flow will error on useReducer(reducer, state, undefined); because the argument count is different than what’s expected.

): [S, Dispatch<A>];

declare export function useReducer<S, A, I>(
reducer: (S, A) => S,
initialArg: I,
init: (I) => S,
): [S, Dispatch<A>];

declare export function useRef<T>(initialValue: ?T): {current: T | null};

Expand Down
24 changes: 24 additions & 0 deletions tests/getters_and_setters/getters_and_setters.diff
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
--- getters_and_setters.exp
+++ getters_and_setters.out
@@ -465,8 +465,8 @@
react.js:17:13
17| (<Example a="bad" />); // error: number ~> string
^^^^^ [1]
- <BUILTINS>/react.js:425:36
- 425| number: React$PropType$Primitive<number>;
+ <BUILTINS>/react.js:438:36
+ 438| number: React$PropType$Primitive<number>;
^^^^^^ [2]


@@ -482,8 +482,8 @@
react.js:18:20
18| (<Example a={0} c={0} />); // error: number ~> string
^ [1]
- <BUILTINS>/react.js:427:36
- 427| string: React$PropType$Primitive<string>;
+ <BUILTINS>/react.js:440:36
+ 440| string: React$PropType$Primitive<string>;
^^^^^^ [2]


116 changes: 116 additions & 0 deletions tests/new_react/new_react.diff
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
--- new_react.exp
+++ new_react.out
@@ -193,8 +193,8 @@
^^^^^^^^^^^^

References:
- <BUILTINS>/react.js:425:36
- 425| number: React$PropType$Primitive<number>;
+ <BUILTINS>/react.js:438:36
+ 438| number: React$PropType$Primitive<number>;
^^^^^^ [1]
classes.js:57:12
57| var _: string = this.props.x;
@@ -420,8 +420,8 @@
^^^^^^^^^^^^

References:
- <BUILTINS>/react.js:425:36
- 425| number: React$PropType$Primitive<number>;
+ <BUILTINS>/react.js:438:36
+ 438| number: React$PropType$Primitive<number>;
^^^^^^ [1]
new_react.js:19:18
19| var qux: string = this.props.z;
@@ -437,8 +437,8 @@
^^^^^^^^^^^^

References:
- <BUILTINS>/react.js:427:36
- 427| string: React$PropType$Primitive<string>;
+ <BUILTINS>/react.js:440:36
+ 440| string: React$PropType$Primitive<string>;
^^^^^^ [1]
new_react.js:20:15
20| var w:number = this.props.x;
@@ -471,8 +471,8 @@
new_react.js:29:23
29| var element = <C x = {0}/>;
^ [1]
- <BUILTINS>/react.js:427:36
- 427| string: React$PropType$Primitive<string>;
+ <BUILTINS>/react.js:440:36
+ 440| string: React$PropType$Primitive<string>;
^^^^^^ [2]


@@ -529,8 +529,8 @@
^^^^^^^^^^^^

References:
- <BUILTINS>/react.js:427:36
- 427| string: React$PropType$Primitive<string>;
+ <BUILTINS>/react.js:440:36
+ 440| string: React$PropType$Primitive<string>;
^^^^^^ [1]
props.js:14:16
14| var a: number = this.props.x; // error
@@ -566,8 +566,8 @@
^^^^^^^^^^^^

References:
- <BUILTINS>/react.js:425:36
- 425| number: React$PropType$Primitive<number>;
+ <BUILTINS>/react.js:438:36
+ 438| number: React$PropType$Primitive<number>;
^^^^^^ [1]
props.js:16:16
16| var c: string = this.props.z; // error
@@ -588,14 +588,14 @@
props.js:20:29
20| var element = <TestProps x={false} y={false} z={false} />; // 3 errors
^^^^^ [1]
- <BUILTINS>/react.js:427:36
- 427| string: React$PropType$Primitive<string>;
+ <BUILTINS>/react.js:440:36
+ 440| string: React$PropType$Primitive<string>;
^^^^^^ [2]
props.js:20:49
20| var element = <TestProps x={false} y={false} z={false} />; // 3 errors
^^^^^ [3]
- <BUILTINS>/react.js:425:36
- 425| number: React$PropType$Primitive<number>;
+ <BUILTINS>/react.js:438:36
+ 438| number: React$PropType$Primitive<number>;
^^^^^^ [4]


@@ -652,8 +652,8 @@
props2.js:9:41
9| getInitialState: function(): { bar: number } {
^^^^^^ [1]
- <BUILTINS>/react.js:427:36
- 427| string: React$PropType$Primitive<string>;
+ <BUILTINS>/react.js:440:36
+ 440| string: React$PropType$Primitive<string>;
^^^^^^ [2]
props2.js:15:42
15| return <C {...this.state} foo = {0} />;
@@ -684,12 +684,12 @@
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

References:
- <BUILTINS>/react.js:401:39
+ <BUILTINS>/react.js:414:39
v
- 401| type ReactPropsChainableTypeChecker = {
- 402| isRequired: ReactPropsCheckType;
- 403| (props: any, propName: string, componentName: string, href?: string): ?Error;
- 404| };
+ 414| type ReactPropsChainableTypeChecker = {
+ 415| isRequired: ReactPropsCheckType;
+ 416| (props: any, propName: string, componentName: string, href?: string): ?Error;
+ 417| };
^ [1]


Loading