Skip to content

Commit

Permalink
Add definition for React.forwardRef()
Browse files Browse the repository at this point in the history
  • Loading branch information
motiz88 committed Oct 22, 2018
1 parent 222a42e commit 0eff6fc
Show file tree
Hide file tree
Showing 11 changed files with 272 additions and 196 deletions.
4 changes: 4 additions & 0 deletions lib/react.js
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,9 @@ declare module react {
): React$ElementFactory<ElementType>;
declare export function createRef<ElementType: React$ElementType>(
): {current: null | React$ElementRef<ElementType>};
declare export function forwardRef<Props, ElementType: React$ElementType>(
render: (props: Props, ref: React$Ref<ElementType>) => React$Node
): React$ComponentType<Props>;

declare export function isValidElement(element: any): boolean;

Expand Down Expand Up @@ -279,6 +282,7 @@ declare module react {
+cloneElement: typeof cloneElement,
+createFactory: typeof createFactory,
+createRef: typeof createRef,
+forwardRef: typeof forwardRef,
+isValidElement: typeof isValidElement,
+Component: typeof Component,
+PureComponent: typeof PureComponent,
Expand Down
8 changes: 4 additions & 4 deletions tests/getters_and_setters/getters_and_setters.exp
Original file line number Diff line number Diff line change
Expand Up @@ -465,8 +465,8 @@ References:
react.js:17:13
17| (<Example a="bad" />); // error: number ~> string
^^^^^ [1]
<BUILTINS>/react.js:326:36
326| number: React$PropType$Primitive<number>;
<BUILTINS>/react.js:330:36
330| number: React$PropType$Primitive<number>;
^^^^^^ [2]


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


Expand Down
46 changes: 23 additions & 23 deletions tests/new_react/new_react.exp
Original file line number Diff line number Diff line change
Expand Up @@ -189,8 +189,8 @@ Cannot assign `this.props.x` to `_` because number [1] is incompatible with stri
^^^^^^^^^^^^

References:
<BUILTINS>/react.js:326:36
326| number: React$PropType$Primitive<number>;
<BUILTINS>/react.js:330:36
330| number: React$PropType$Primitive<number>;
^^^^^^ [1]
classes.js:57:12
57| var _: string = this.props.x;
Expand Down Expand Up @@ -388,8 +388,8 @@ Cannot assign `this.props.z` to `qux` because:
^^^^^^^^^^^^

References:
<BUILTINS>/react.js:326:36
326| number: React$PropType$Primitive<number>;
<BUILTINS>/react.js:330:36
330| number: React$PropType$Primitive<number>;
^^^^^^ [1]
new_react.js:19:18
19| var qux: string = this.props.z;
Expand All @@ -405,8 +405,8 @@ Cannot assign `this.props.x` to `w` because string [1] is incompatible with numb
^^^^^^^^^^^^

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


Expand Down Expand Up @@ -545,8 +545,8 @@ Cannot assign `this.props.x` to `a` because:
^^^^^^^^^^^^

References:
<BUILTINS>/react.js:328:36
328| string: React$PropType$Primitive<string>;
<BUILTINS>/react.js:332:36
332| string: React$PropType$Primitive<string>;
^^^^^^ [1]
props.js:14:16
14| var a: number = this.props.x; // error
Expand Down Expand Up @@ -582,8 +582,8 @@ Cannot assign `this.props.z` to `c` because:
^^^^^^^^^^^^

References:
<BUILTINS>/react.js:326:36
326| number: React$PropType$Primitive<number>;
<BUILTINS>/react.js:330:36
330| number: React$PropType$Primitive<number>;
^^^^^^ [1]
props.js:16:16
16| var c: string = this.props.z; // error
Expand All @@ -604,14 +604,14 @@ References:
props.js:20:29
20| var element = <TestProps x={false} y={false} z={false} />; // 3 errors
^^^^^ [1]
<BUILTINS>/react.js:328:36
328| string: React$PropType$Primitive<string>;
<BUILTINS>/react.js:332:36
332| 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:326:36
326| number: React$PropType$Primitive<number>;
<BUILTINS>/react.js:330:36
330| number: React$PropType$Primitive<number>;
^^^^^^ [4]


Expand Down Expand Up @@ -668,8 +668,8 @@ References:
props2.js:9:41
9| getInitialState: function(): { bar: number } {
^^^^^^ [1]
<BUILTINS>/react.js:328:36
328| string: React$PropType$Primitive<string>;
<BUILTINS>/react.js:332:36
332| string: React$PropType$Primitive<string>;
^^^^^^ [2]
props2.js:15:42
15| return <C {...this.state} foo = {0} />;
Expand Down Expand Up @@ -700,12 +700,12 @@ Cannot get `React.PropTypes.string.inRequired` because property `inRequired` is
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

References:
<BUILTINS>/react.js:302:39
<BUILTINS>/react.js:306:39
v
302| type ReactPropsChainableTypeChecker = {
303| isRequired: ReactPropsCheckType;
304| (props: any, propName: string, componentName: string, href?: string): ?Error;
305| };
306| type ReactPropsChainableTypeChecker = {
307| isRequired: ReactPropsCheckType;
308| (props: any, propName: string, componentName: string, href?: string): ?Error;
309| };
^ [1]


Expand Down
Loading

0 comments on commit 0eff6fc

Please sign in to comment.