Skip to content

Commit

Permalink
[flow] Remove react.ref_as_prop=disabled override in component_synt…
Browse files Browse the repository at this point in the history
…ax test suite

Summary:
The behavior remains mostly the same. The test is asserting that we are actually ignoring the ref prop in component spread.

Before, we ignore it and subtype the ref prop in jsx against `React.ElementRef<typeof Component>`, which gives back `React.RefSetter<void>` and explains the previous error.

Now with ref-as-prop, the ref prop appears as regular prop and subtype against the entire props object with spreaded ref prop intentionally dropped, so we get the prop-missing error.

Changelog: [internal]

Reviewed By: panagosg7

Differential Revision: D66849734

fbshipit-source-id: 870ed0bc794f76bf7daf15eef45862f9a5db053b
  • Loading branch information
SamChou19815 authored and facebook-github-bot committed Dec 16, 2024
1 parent 5f4e844 commit f32b9ac
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 27 deletions.
1 change: 0 additions & 1 deletion tests/component_syntax/.flowconfig
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ component_syntax=true
experimental.component_syntax.hook_compatibility=true
all=true
no_flowlib=false
react.ref_as_prop=disabled

[lints]
nested-component=error
Expand Down
50 changes: 24 additions & 26 deletions tests/component_syntax/component_syntax.exp
Original file line number Diff line number Diff line change
Expand Up @@ -217,23 +217,22 @@ References:
^^^ [1]


Error ---------------------------------------------------------------------------------------------- annotation.js:52:17
Error ----------------------------------------------------------------------------------------------- annotation.js:52:2

Cannot create `SpreadRef` element because in property `ref`: [incompatible-type]
- Either number [1] is incompatible with object type [2].
- Or number [1] is incompatible with function type [3].
Cannot create `SpreadRef` element because property `ref` is missing in object type [1] but exists in props [2].
[prop-missing]

annotation.js:52:17
52| <SpreadRef ref={1} />; // error: string and number refs are still not allowed
^ [1]
annotation.js:52:2
52| <SpreadRef ref={1} />; // error: string and number refs are still not allowed
^^^^^^^^^

References:
<BUILTINS>/react.js:196:5
196| | { -current: T | null, ... }
^^^^^^^^^^^^^^^^^^^^^^^^^^^ [2]
<BUILTINS>/react.js:197:6
197| | ((T | null) => mixed)
^^^^^^^^^^^^^^^^^^^ [3]
annotation.js:51:40
51| declare var SpreadRef: component(...p: {ref: number}); // error
^^^^^^^^^^^^^ [1]
annotation.js:52:1
52| <SpreadRef ref={1} />; // error: string and number refs are still not allowed
^^^^^^^^^^^^^^^^^^^^^ [2]


Error ---------------------------------------------------------------------------------------------- annotation.js:54:57
Expand Down Expand Up @@ -1249,23 +1248,22 @@ References:
^^^ [1]


Error ------------------------------------------------------------------------------------------------ declared.js:54:17
Error ------------------------------------------------------------------------------------------------- declared.js:54:2

Cannot create `SpreadRef` element because in property `ref`: [incompatible-type]
- Either number [1] is incompatible with object type [2].
- Or number [1] is incompatible with function type [3].
Cannot create `SpreadRef` element because property `ref` is missing in object type [1] but exists in props [2].
[prop-missing]

declared.js:54:17
54| <SpreadRef ref={1} />; // error: string and number refs are still not allowed
^ [1]
declared.js:54:2
54| <SpreadRef ref={1} />; // error: string and number refs are still not allowed
^^^^^^^^^

References:
<BUILTINS>/react.js:196:5
196| | { -current: T | null, ... }
^^^^^^^^^^^^^^^^^^^^^^^^^^^ [2]
<BUILTINS>/react.js:197:6
197| | ((T | null) => mixed)
^^^^^^^^^^^^^^^^^^^ [3]
declared.js:53:35
53| declare component SpreadRef(...p: {ref: number}); // error
^^^^^^^^^^^^^ [1]
declared.js:54:1
54| <SpreadRef ref={1} />; // error: string and number refs are still not allowed
^^^^^^^^^^^^^^^^^^^^^ [2]


Error ------------------------------------------------------------------------------------------------ declared.js:56:52
Expand Down

0 comments on commit f32b9ac

Please sign in to comment.