Skip to content

Commit

Permalink
Add definition for React.forwardRef()
Browse files Browse the repository at this point in the history
Closes #6103
  • Loading branch information
motiz88 committed Jun 23, 2018
1 parent 0942ae9 commit a704436
Show file tree
Hide file tree
Showing 9 changed files with 265 additions and 189 deletions.
4 changes: 4 additions & 0 deletions lib/react.js
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,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 @@ -266,6 +269,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
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:313:36
313| number: React$PropType$Primitive<number>;
<BUILTINS>/react.js:317:36
317| 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:313:36
313| number: React$PropType$Primitive<number>;
<BUILTINS>/react.js:317:36
317| 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:315:36
315| string: React$PropType$Primitive<string>;
<BUILTINS>/react.js:319:36
319| 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:315:36
315| string: React$PropType$Primitive<string>;
<BUILTINS>/react.js:319:36
319| 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:315:36
315| string: React$PropType$Primitive<string>;
<BUILTINS>/react.js:319:36
319| 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:313:36
313| number: React$PropType$Primitive<number>;
<BUILTINS>/react.js:317:36
317| 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:315:36
315| string: React$PropType$Primitive<string>;
<BUILTINS>/react.js:319:36
319| 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:313:36
313| number: React$PropType$Primitive<number>;
<BUILTINS>/react.js:317:36
317| 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:315:36
315| string: React$PropType$Primitive<string>;
<BUILTINS>/react.js:319:36
319| 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:289:39
<BUILTINS>/react.js:293:39
v
289| type ReactPropsChainableTypeChecker = {
290| isRequired: ReactPropsCheckType;
291| (props: any, propName: string, componentName: string, href?: string): ?Error;
292| };
293| type ReactPropsChainableTypeChecker = {
294| isRequired: ReactPropsCheckType;
295| (props: any, propName: string, componentName: string, href?: string): ?Error;
296| };
^ [1]


Expand Down
Loading

0 comments on commit a704436

Please sign in to comment.