Skip to content
Permalink
Browse files

[ty] Make React.ElementConfig et al. utility types

Summary: It's easier to handle these cases as utility types rather than raw strings.

Reviewed By: samwgoldman

Differential Revision: D15055623

fbshipit-source-id: 7828fd630fbce548a68fdc670a589806404b722f
  • Loading branch information...
panagosg7 authored and facebook-github-bot committed Apr 25, 2019
1 parent 5c9b150 commit 2ac4372e31a1f3a03ae963ed7a89b2118b862aad
Showing with 18 additions and 5 deletions.
  1. +14 −1 src/common/ty/ty.ml
  2. +4 −4 src/typing/ty_normalizer.ml
@@ -139,8 +139,8 @@ and type_param = {

and opt = bool

(* https://flow.org/en/docs/types/utilities/ *)
and utility =
(* https://flow.org/en/docs/types/utilities/ *)
| Keys of t
| Values of t
| ReadOnly of t
@@ -159,6 +159,11 @@ and utility =
| Supertype of t
| Subtype of t
| Exists
(* React utils *)
| ReactElementPropsType of t
| ReactElementConfigType of t
| ReactElementRefType of t
| ReactConfigType of t * t

and polarity = Positive | Negative | Neutral
[@@deriving visitors {
@@ -303,6 +308,10 @@ let string_of_utility_ctor = function
| Supertype _ -> "$Supertype"
| Subtype _ -> "$Subtype"
| Exists -> "*"
| ReactElementPropsType _ -> "React$ElementProps"
| ReactElementConfigType _ -> "React$ElementConfig"
| ReactElementRefType _ -> "React$ElementRef"
| ReactConfigType _ -> "React$Config"

let types_of_utility = function
| Keys t -> Some [t]
@@ -323,3 +332,7 @@ let types_of_utility = function
| Supertype t -> Some [t]
| Subtype t -> Some [t]
| Exists -> None
| ReactElementPropsType t -> Some [t]
| ReactElementConfigType t -> Some [t]
| ReactElementRefType t -> Some [t]
| ReactConfigType (t1, t2) -> Some [t1; t2]
@@ -1505,12 +1505,12 @@ end = struct
| T.RestType (T.Object.Rest.IgnoreExactAndOwn, t') ->
type__ ~env t' >>| fun ty' -> Ty.Utility (Ty.Diff (ty, ty'))
| T.SpreadType (target, ts) -> spread ~env ty target ts
| T.ReactElementPropsType -> return (generic_builtin_t "React$ElementProps" [ty])
| T.ReactElementConfigType -> return (generic_builtin_t "React$ElementConfig" [ty])
| T.ReactElementRefType -> return (generic_builtin_t "React$ElementRef" [ty])
| T.ReactElementPropsType -> return (Ty.Utility (Ty.ReactElementPropsType ty))
| T.ReactElementConfigType -> return (Ty.Utility (Ty.ReactElementConfigType ty))
| T.ReactElementRefType -> return (Ty.Utility (Ty.ReactElementRefType ty))
| T.ReactConfigType default_props ->
type__ ~env default_props >>| fun default_props' ->
generic_builtin_t "React$Config" [ty; default_props']
Ty.Utility (Ty.ReactConfigType (ty, default_props'))
| T.RestType (T.Object.Rest.ReactConfigMerge _, _)
| T.Bind _ as d ->
terr ~kind:BadEvalT ~msg:(Debug_js.string_of_destructor d) None

0 comments on commit 2ac4372

Please sign in to comment.
You can’t perform that action at this time.