Skip to content

Commit

Permalink
[flow] Stop suggesting React$MixedElement and React$Node
Browse files Browse the repository at this point in the history
Summary:
These types can be used without import, so the logic is no longer necessary. It will help stop the bleed of introducing more of these internal types.

Changelog: [internal]

Reviewed By: gkz

Differential Revision: D67480565

fbshipit-source-id: 6bfbc3e645ee15ffe905097f37991892e7725ce9
  • Loading branch information
SamChou19815 authored and facebook-github-bot committed Dec 19, 2024
1 parent 94bc21d commit 4598839
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 19 deletions.
18 changes: 4 additions & 14 deletions src/services/code_action/insert_type_utils.ml
Original file line number Diff line number Diff line change
Expand Up @@ -1212,13 +1212,8 @@ class type_normalization_hardcoded_fixes_mapper
kind,
Some [(Ty.Str _ | Ty.StrLit _)]
)
when is_react_loc sym_def_loc && imports_react ->
let name =
if imports_react then
"React.MixedElement"
else
"React$MixedElement"
in
when is_react_loc sym_def_loc ->
let name = "React.MixedElement" in
let symbol = { symbol with Ty.sym_name = Reason.OrdinaryName name } in
this#on_t env Ty.(Generic (symbol, kind, None))
(* E.g. React$Element<typeof A> will become React.MixedElement or React.Node.
Expand All @@ -1238,14 +1233,9 @@ class type_normalization_hardcoded_fixes_mapper
when is_react_loc sym_def_loc ->
let name =
if generalize_react_mixed_element then
if imports_react then
"React.MixedElement"
else
"React$MixedElement"
else if imports_react then
"React.Node"
"React.MixedElement"
else
"React$Node"
"React.Node"
in
let symbol = { symbol with Ty.sym_name = Reason.OrdinaryName name } in
this#on_t env Ty.(Generic (symbol, kind, None))
Expand Down
4 changes: 2 additions & 2 deletions tests/annotate_exports_react/annotate_exports_react.exp
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import React from 'react';

type Props = {}

export default (): React$MixedElement => {
export default (): React.MixedElement => {
class Abc extends React.Component<Props> { }
return <Abc/>;
}
Expand Down Expand Up @@ -151,7 +151,7 @@ import React from 'react';

type Props = {}

export default (): React$MixedElement => {
export default (): React.MixedElement => {
class Abc extends React.Component<Props> { }
return <Abc/>;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

declare function f(): ExactReactElement_DEPRECATED<'a'> | ExactReactElement_DEPRECATED<'b'>;

module.exports = (f() as React$MixedElement);
module.exports = (f() as React.MixedElement);

>>> Launching report...

Expand Down Expand Up @@ -42,7 +42,7 @@ Warnings:

declare function f(): ExactReactElement_DEPRECATED<'a'> | ExactReactElement_DEPRECATED<'b'>;

module.exports = (f() as React$MixedElement);
module.exports = (f() as React.MixedElement);


=== Diff between codemod-ed & autofix-ed ===
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@

declare function f(): ExactReactElement_DEPRECATED<'a'> | ExactReactElement_DEPRECATED<'b'>;

module.exports = (f() as React$MixedElement);
module.exports = (f() as React.MixedElement);
> flow status
No errors!

0 comments on commit 4598839

Please sign in to comment.