Skip to content

Commit

Permalink
[react] reserve React$AbstractComponent
Browse files Browse the repository at this point in the history
Summary:
Adds React$AbstractComponent as a built-in that expects 3 type arguments. I'll be building out the functionality of this type in stacked diffs.

OSS Users: I will follow up with a blog post when we get closer to having this type actually be usable. We expect it to improve the precision and speed with which flow can typecheck React components.

Reviewed By: samwgoldman

Differential Revision: D12925858

fbshipit-source-id: e242dbf74ed2b90eca3fb7f66641bee8b919e530
  • Loading branch information
jbrown215 authored and facebook-github-bot committed Nov 13, 2018
1 parent d0ac7d9 commit 16dc39a
Show file tree
Hide file tree
Showing 6 changed files with 62 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/typing/debug_js.ml
Original file line number Diff line number Diff line change
Expand Up @@ -2813,3 +2813,5 @@ let dump_flow_error =
spf "EUnexpectedTemporaryBaseType (%s)" (string_of_aloc loc)
| ESignatureVerification sve ->
spf "ESignatureVerification (%s)" (Signature_builder_deps.With_ALoc.Error.debug_to_string sve)
| EAbstractComponentNotYetSupported loc ->
spf "EAbstractComponentNotYetSupported (%s)" (string_of_aloc loc)
5 changes: 5 additions & 0 deletions src/typing/flow_error.ml
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,7 @@ type error_message =
| EDeprecatedCallSyntax of ALoc.t
| EUnexpectedTemporaryBaseType of ALoc.t
| ESignatureVerification of Signature_builder_deps.With_ALoc.Error.t
| EAbstractComponentNotYetSupported of ALoc.t

and binding_error =
| ENameAlreadyBound
Expand Down Expand Up @@ -399,6 +400,7 @@ let util_use_op_of_msg nope util = function
| EDeprecatedCallSyntax _
| EUnexpectedTemporaryBaseType _
| ESignatureVerification _
| EAbstractComponentNotYetSupported _
-> nope

(* Rank scores for signals of different strength on an x^2 scale so that greater
Expand Down Expand Up @@ -1883,6 +1885,9 @@ let rec error_of_msg ~trace_reasons ~source_file =
]
end

| EAbstractComponentNotYetSupported loc ->
mk_error ~trace_infos loc [text "React$AbstractComponent is not supported yet."]

| EUnreachable loc ->
mk_error ~trace_infos ~kind:InferWarning loc
[text "Unreachable code."]
Expand Down
4 changes: 4 additions & 0 deletions src/typing/type_annotation.ml
Original file line number Diff line number Diff line change
Expand Up @@ -584,6 +584,10 @@ let rec convert cx tparams_map = Ast.Type.(function
| "$ComposeReverse" ->
mk_custom_fun cx loc targs ident (Compose true)

| "React$AbstractComponent" ->
check_type_arg_arity cx loc targs 3 (fun () ->
error_type cx loc (FlowError.EAbstractComponentNotYetSupported loc)
)
| "React$PropType$Primitive" ->
check_type_arg_arity cx loc targs 1 (fun () ->
let ts, targs = convert_type_params () in
Expand Down
Empty file.
34 changes: 34 additions & 0 deletions tests/react_abstract_component/react_abstract_component.exp
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
Error ----------------------------------------------------------------------------------------------------- test.js:3:19

React$AbstractComponent is not supported yet.

3| function test1(x: React$AbstractComponent<any, any, any>) { // Error not yet supported
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^


Error ----------------------------------------------------------------------------------------------------- test.js:7:19

Cannot use type without exactly 3 type arguments.

7| function test2(x: React$AbstractComponent<any>) { // Not enough targs
^^^^^^^^^^^^^^^^^^^^^^^^^^^^


Error ---------------------------------------------------------------------------------------------------- test.js:11:19

Cannot use type without exactly 3 type arguments.

11| function test3(x: React$AbstractComponent<any,any>) { // Not enough targs
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^


Error ---------------------------------------------------------------------------------------------------- test.js:15:19

Cannot use type without exactly 3 type arguments.

15| function test4(x: React$AbstractComponent<any,any,any,any>) { // Too many targs
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^



Found 4 errors
17 changes: 17 additions & 0 deletions tests/react_abstract_component/test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
//@flow

function test1(x: React$AbstractComponent<any, any, any>) { // Error not yet supported
return x;
}

function test2(x: React$AbstractComponent<any>) { // Not enough targs
return x;
}

function test3(x: React$AbstractComponent<any,any>) { // Not enough targs
return x;
}

function test4(x: React$AbstractComponent<any,any,any,any>) { // Too many targs
return x;
}

0 comments on commit 16dc39a

Please sign in to comment.