From 505d1ab7b8a3f3281634c9b1cc98387968e63514 Mon Sep 17 00:00:00 2001 From: Sam Zhou Date: Wed, 20 Mar 2024 09:55:25 -0700 Subject: [PATCH] [flow] Drop support for $Compose and $ComposeReverse Summary: I want to get rid of some of the $ types that it's not really used widely and reduces some custom functions that we don't always get right. Changelog: [errors] Support for $Compose and $ComposeReverse types are removed. We recommend to use overloads to approximate their behavior instead. e.g. ``` declare export function compose(): (a: T) => T; declare export function compose) => mixed>( f: F, ): F; declare export function compose, R>( f1: (a: A) => R, f2: (...T) => A, ): (...T) => R; declare export function compose, R>( f1: (b: B) => R, f2: (a: A) => B, f3: (...T) => A, ): (...T) => R; declare export function compose, R>( f1: (c: C) => R, f2: (b: B) => C, f3: (a: A) => B, f4: (...T) => A, ): (...T) => R; declare export function compose( f1: (b: any) => R, ...funcs: $ReadOnlyArray<(...$ReadOnlyArray) => mixed> ): (...$ReadOnlyArray) => R; declare export function compose( ...funcs: $ReadOnlyArray<(...$ReadOnlyArray) => mixed> ): (...$ReadOnlyArray) => R; ``` Reviewed By: panagosg7 Differential Revision: D55048197 fbshipit-source-id: c8f15f6f274a4d9b8e3acafec0a8bd30e5dd7529 --- src/parser_utils/type_sig/type_sig.ml | 2 - src/parser_utils/type_sig/type_sig_parse.ml | 10 -- src/typing/custom_fun_kit.ml | 97 -------------- src/typing/debug_js.ml | 2 - src/typing/flow_js.ml | 10 +- src/typing/ty_normalizer.ml | 8 +- src/typing/type.ml | 2 - src/typing/type_annotation.ml | 2 - src/typing/type_mapper.ml | 1 - src/typing/type_sig_merge.ml | 6 - src/typing/type_visitor.ml | 1 - tests/any/any.exp | 28 ++-- tests/any/ex_special_cases.js | 3 - .../babel_loose_array_spread.exp | 30 +---- tests/babel_loose_array_spread/compose.js | 14 -- .../babel_loose_array_spread/passing_cases.js | 5 +- tests/compose/.flowconfig | 7 - tests/compose/basic.js | 16 --- tests/compose/compose.exp | 122 ------------------ tests/compose/lib/recompose.js | 3 - tests/compose/recompose.js | 25 ---- tests/compose/spread.js | 4 - tests/react_hocs/hocs.js | 6 +- tests/react_hocs/react_hocs.exp | 10 +- 24 files changed, 32 insertions(+), 382 deletions(-) delete mode 100644 tests/babel_loose_array_spread/compose.js delete mode 100644 tests/compose/.flowconfig delete mode 100644 tests/compose/basic.js delete mode 100644 tests/compose/compose.exp delete mode 100644 tests/compose/lib/recompose.js delete mode 100644 tests/compose/recompose.js delete mode 100644 tests/compose/spread.js diff --git a/src/parser_utils/type_sig/type_sig.ml b/src/parser_utils/type_sig/type_sig.ml index 8332cd50697..c464db8d2a0 100644 --- a/src/parser_utils/type_sig/type_sig.ml +++ b/src/parser_utils/type_sig/type_sig.ml @@ -597,8 +597,6 @@ type ('loc, 'a) annot = | Object_assign of 'loc | Object_getPrototypeOf of 'loc | Object_setPrototypeOf of 'loc - | Compose of 'loc - | ComposeReverse of 'loc | ReactAbstractComponent of { loc: 'loc; config: 'a; diff --git a/src/parser_utils/type_sig/type_sig_parse.ml b/src/parser_utils/type_sig/type_sig_parse.ml index adb5c20bc58..f5fd38640ee 100644 --- a/src/parser_utils/type_sig/type_sig_parse.ml +++ b/src/parser_utils/type_sig/type_sig_parse.ml @@ -2520,16 +2520,6 @@ and maybe_special_unqualified_generic opts scope tbls xs loc targs ref_loc = Annot (ReactElementRef (loc, t)) | _ -> Err (loc, CheckError) end - | "$Compose" -> begin - match targs with - | None -> Annot (Compose loc) - | _ -> Err (loc, CheckError) - end - | "$ComposeReverse" -> begin - match targs with - | None -> Annot (ComposeReverse loc) - | _ -> Err (loc, CheckError) - end | "$Flow$DebugPrint" -> begin match targs with | None -> Annot (FlowDebugPrint loc) diff --git a/src/typing/custom_fun_kit.ml b/src/typing/custom_fun_kit.ml index ba213ee9b23..b9550753f40 100644 --- a/src/typing/custom_fun_kit.ml +++ b/src/typing/custom_fun_kit.ml @@ -26,106 +26,9 @@ end module Kit (Flow : Flow_common.S) : CUSTOM_FUN = struct include Flow - module PinTypes = Implicit_instantiation.PinTypes (Flow) - - (* Creates the appropriate constraints for the compose() function and its - * reversed variant. *) - let rec run_compose cx trace ~use_op reason_op reverse fns spread_fn tin tout = - match (reverse, fns, spread_fn) with - (* Call the tail functions in our array first and call our head function - * last after that. *) - | (false, fn :: fns, _) -> - let reason = replace_desc_reason (RCustom "compose intermediate value") (reason_of_t fn) in - let tvar = - Tvar.mk_no_wrap_where cx reason (fun tvar -> - run_compose cx trace ~use_op reason_op reverse fns spread_fn tin tvar - ) - in - rec_flow - cx - trace - ( fn, - CallT - { - use_op; - reason; - call_action = - Funcalltype - (mk_functioncalltype ~call_kind:RegularCallKind reason_op None [Arg tvar] tout); - return_hint = Type.hint_unavailable; - } - ) - (* If the compose function is reversed then we want to call the tail - * functions in our array after we call the head function. *) - | (true, fn :: fns, _) -> - let reason = replace_desc_reason (RCustom "compose intermediate value") (reason_of_t fn) in - let tvar = Tvar.mk_no_wrap cx reason in - rec_flow - cx - trace - ( fn, - CallT - { - use_op; - reason; - call_action = - Funcalltype - (mk_functioncalltype - ~call_kind:RegularCallKind - reason_op - None - [Arg (OpenT tin)] - (reason, tvar) - ); - return_hint = Type.hint_unavailable; - } - ); - run_compose cx trace ~use_op reason_op reverse fns spread_fn (reason, tvar) tout - (* If there are no functions and no spread function then we are an identity - * function. *) - | (_, [], None) -> rec_flow_t ~use_op:unknown_use cx trace (OpenT tin, OpenT tout) - | (_, [], Some spread_fn) -> - Flow_js_utils.add_output - cx - Error_message.( - EUnsupportedSyntax (spread_fn |> TypeUtil.reason_of_t |> loc_of_reason, SpreadArgument) - ); - rec_flow_t cx ~use_op:unknown_use trace (AnyT.error reason_op, OpenT tin); - rec_flow_t cx ~use_op:unknown_use trace (AnyT.error reason_op, OpenT tout) let run cx trace ~use_op ~return_hint reason_op kind args spread_arg tout = match kind with - | Compose reverse -> - (* Drop the specific argument reasons since run_compose will emit CallTs - * with completely unrelated argument reasons. *) - let use_op = - match use_op with - | Op (FunCall { op; fn; args = _; local }) -> Op (FunCall { op; fn; args = []; local }) - | Op (FunCallMethod { op; fn; prop; args = _; local }) -> - Op (FunCallMethod { op; fn; prop; args = []; local }) - | _ -> use_op - in - let tin = (reason_op, Tvar.mk_no_wrap cx reason_op) in - let tvar = (reason_op, Tvar.mk_no_wrap cx reason_op) in - run_compose cx trace ~use_op reason_op reverse args spread_arg tin tvar; - let tin = - let tin' = (reason_op, Tvar.mk_no_wrap cx reason_op) in - unify cx (OpenT tin') (PinTypes.pin_type cx ~use_op:unknown_use reason_op (OpenT tin)); - tin' - in - let funt = - FunT - ( dummy_static reason_op, - mk_functiontype - reason_op - [OpenT tin] - ~rest_param:None - ~def_reason:reason_op - ~predicate:None - (OpenT tvar) - ) - in - rec_flow_t ~use_op:unknown_use cx trace (DefT (reason_op, funt), tout) | ReactCreateElement -> (match args with (* React.createElement(component) *) diff --git a/src/typing/debug_js.ml b/src/typing/debug_js.ml index d13ed52cd3c..9c55509ab2d 100644 --- a/src/typing/debug_js.ml +++ b/src/typing/debug_js.ml @@ -126,8 +126,6 @@ let rec dump_t_ (depth, tvars) cx t = | ObjectAssign -> "ObjectAssign" | ObjectGetPrototypeOf -> "ObjectGetPrototypeOf" | ObjectSetPrototypeOf -> "ObjectSetPrototypeOf" - | Compose false -> "Compose" - | Compose true -> "ComposeReverse" | ReactCreateElement -> "ReactCreateElement" | ReactCloneElement -> "ReactCloneElement" | ReactElementFactory _ -> "ReactElementFactory" diff --git a/src/typing/flow_js.ml b/src/typing/flow_js.ml index c350bfa3edd..9ace85fe9c5 100644 --- a/src/typing/flow_js.ml +++ b/src/typing/flow_js.ml @@ -3318,7 +3318,7 @@ struct | ( CustomFunT ( _, ( ObjectAssign | ObjectGetPrototypeOf | ObjectSetPrototypeOf | DebugPrint - | DebugThrow | DebugSleep | Compose _ | ReactCreateElement | ReactCloneElement + | DebugThrow | DebugSleep | ReactCreateElement | ReactCloneElement | ReactElementFactory _ ) ), CallT { use_op; call_action = ConcretizeCallee tout; _ } @@ -3404,11 +3404,7 @@ struct rec_flow cx trace (t, DebugSleepT reason_op); rec_flow_t cx ~use_op trace (VoidT.why reason_op, OpenT call_tout) | ( CustomFunT - ( lreason, - ( (Compose _ | ReactCreateElement | ReactCloneElement | ReactElementFactory _) as - kind - ) - ), + (lreason, ((ReactCreateElement | ReactCloneElement | ReactElementFactory _) as kind)), CallT { use_op; reason = reason_op; call_action = Funcalltype calltype; return_hint } ) -> let { @@ -6815,7 +6811,6 @@ struct | UseT (_, CustomFunT (_, ObjectAssign)) | UseT (_, CustomFunT (_, ObjectGetPrototypeOf)) | UseT (_, CustomFunT (_, ObjectSetPrototypeOf)) - | UseT (_, CustomFunT (_, Compose _)) | UseT (_, CustomFunT (_, ReactCreateElement)) | UseT (_, CustomFunT (_, ReactCloneElement)) | UseT (_, CustomFunT (_, DebugPrint)) @@ -6912,7 +6907,6 @@ struct | CustomFunT (_, ObjectAssign) | CustomFunT (_, ObjectGetPrototypeOf) | CustomFunT (_, ObjectSetPrototypeOf) - | CustomFunT (_, Compose _) | CustomFunT (_, ReactCreateElement) | CustomFunT (_, ReactCloneElement) | CustomFunT (_, DebugThrow) diff --git a/src/typing/ty_normalizer.ml b/src/typing/ty_normalizer.ml index 92b93b66682..4ffdaae2e28 100644 --- a/src/typing/ty_normalizer.ml +++ b/src/typing/ty_normalizer.ml @@ -1412,7 +1412,7 @@ module Make (I : INPUT) : S = struct in generic_talias opaque_symbol targs - and custom_fun_expanded ~env = + and custom_fun_expanded = Type.( function (* Object.assign: (target: any, ...sources: Array): any *) @@ -1498,8 +1498,6 @@ module Make (I : INPUT) : S = struct let f2 = mk_fun ~tparams ~params (ReturnType reactElement) in mk_inter (f1, [f2]) ) - (* Fallback *) - | t -> custom_fun_short ~env t ) and subst_name ~env loc t bound name = @@ -1558,8 +1556,6 @@ module Make (I : INPUT) : S = struct | ObjectAssign -> return (builtin_t (Reason.OrdinaryName "Object$Assign")) | ObjectGetPrototypeOf -> return (builtin_t (Reason.OrdinaryName "Object$GetPrototypeOf")) | ObjectSetPrototypeOf -> return (builtin_t (Reason.OrdinaryName "Object$SetPrototypeOf")) - | Compose false -> return (builtin_t (Reason.OrdinaryName "$Compose")) - | Compose true -> return (builtin_t (Reason.OrdinaryName "$ComposeReverse")) | ReactCreateElement -> return (builtin_t (Reason.OrdinaryName "React$CreateElement")) | ReactCloneElement -> return (builtin_t (Reason.OrdinaryName "React$CloneElement")) | ReactElementFactory t -> @@ -1572,7 +1568,7 @@ module Make (I : INPUT) : S = struct and custom_fun ~env t = if Env.expand_internal_types env then - custom_fun_expanded ~env t + custom_fun_expanded t else custom_fun_short ~env t diff --git a/src/typing/type.ml b/src/typing/type.ml index 53dea2000b7..6fb42c3a179 100644 --- a/src/typing/type.ml +++ b/src/typing/type.ml @@ -1734,8 +1734,6 @@ module rec TypeTerm : sig | ObjectAssign | ObjectGetPrototypeOf | ObjectSetPrototypeOf - (* common community functions *) - | Compose of bool (* 3rd party libs *) | ReactCreateElement | ReactCloneElement diff --git a/src/typing/type_annotation.ml b/src/typing/type_annotation.ml index ffe17d619f3..cb212ebf433 100644 --- a/src/typing/type_annotation.ml +++ b/src/typing/type_annotation.ml @@ -1216,8 +1216,6 @@ module Make (ConsGen : Type_annotation_sig.ConsGen) (Statement : Statement_sig.S | "Object$Assign" -> mk_custom_fun cx loc t_ast targs ident ObjectAssign | "Object$GetPrototypeOf" -> mk_custom_fun cx loc t_ast targs ident ObjectGetPrototypeOf | "Object$SetPrototypeOf" -> mk_custom_fun cx loc t_ast targs ident ObjectSetPrototypeOf - | "$Compose" -> mk_custom_fun cx loc t_ast targs ident (Compose false) - | "$ComposeReverse" -> mk_custom_fun cx loc t_ast targs ident (Compose true) | "React$AbstractComponent" -> let reason = mk_reason (RCustom "AbstractComponent") loc in (match targs with diff --git a/src/typing/type_mapper.ml b/src/typing/type_mapper.ml index 125fe230c9a..4ec141708a1 100644 --- a/src/typing/type_mapper.ml +++ b/src/typing/type_mapper.ml @@ -752,7 +752,6 @@ class virtual ['a] t = | ObjectAssign | ObjectGetPrototypeOf | ObjectSetPrototypeOf - | Compose _ | ReactCreateElement | ReactCloneElement | DebugPrint diff --git a/src/typing/type_sig_merge.ml b/src/typing/type_sig_merge.ml index e4596e2d409..ea7cc096a39 100644 --- a/src/typing/type_sig_merge.ml +++ b/src/typing/type_sig_merge.ml @@ -891,12 +891,6 @@ and merge_annot env file = function | Object_setPrototypeOf loc -> let reason = Reason.(mk_reason RFunctionType loc) in Type.CustomFunT (reason, Type.ObjectSetPrototypeOf) - | Compose loc -> - let reason = Reason.(mk_reason RFunctionType loc) in - Type.CustomFunT (reason, Type.Compose false) - | ComposeReverse loc -> - let reason = Reason.(mk_reason RFunctionType loc) in - Type.CustomFunT (reason, Type.Compose true) | ReactAbstractComponent { loc; config; instance; renders } -> let reason = Reason.(mk_reason (RCustom "AbstractComponent") loc) in let config = merge env file config in diff --git a/src/typing/type_visitor.ml b/src/typing/type_visitor.ml index 89b9309f032..49df9e1d707 100644 --- a/src/typing/type_visitor.ml +++ b/src/typing/type_visitor.ml @@ -280,7 +280,6 @@ class ['a] t = | ObjectAssign | ObjectGetPrototypeOf | ObjectSetPrototypeOf - | Compose _ | ReactCreateElement | ReactCloneElement | DebugPrint diff --git a/tests/any/any.exp b/tests/any/any.exp index c6e520a1afb..bbb2c86366a 100644 --- a/tests/any/any.exp +++ b/tests/any/any.exp @@ -15,38 +15,38 @@ References: ^^^^^^ [2] -Error ---------------------------------------------------------------------------------------- ex_special_cases.js:39:21 +Error ---------------------------------------------------------------------------------------- ex_special_cases.js:36:21 Cannot assign `array[receiver.name]` to `test1` because number [1] is incompatible with string [2]. [incompatible-type] - ex_special_cases.js:39:21 - 39| var test1: string = array[receiver.name]; // if result of receiver.getprop is any, this will fail, but no error if it's empty. + ex_special_cases.js:36:21 + 36| var test1: string = array[receiver.name]; // if result of receiver.getprop is any, this will fail, but no error if it's empty. ^^^^^^^^^^^^^^^^^^^^ References: - ex_special_cases.js:38:26 - 38| declare var array: Array; + ex_special_cases.js:35:26 + 35| declare var array: Array; ^^^^^^ [1] - ex_special_cases.js:39:12 - 39| var test1: string = array[receiver.name]; // if result of receiver.getprop is any, this will fail, but no error if it's empty. + ex_special_cases.js:36:12 + 36| var test1: string = array[receiver.name]; // if result of receiver.getprop is any, this will fail, but no error if it's empty. ^^^^^^ [2] -Error ---------------------------------------------------------------------------------------- ex_special_cases.js:40:21 +Error ---------------------------------------------------------------------------------------- ex_special_cases.js:37:21 Cannot assign `array[receiver.name()]` to `test2` because number [1] is incompatible with string [2]. [incompatible-type] - ex_special_cases.js:40:21 - 40| var test2: string = array[receiver.name()] // likewise + ex_special_cases.js:37:21 + 37| var test2: string = array[receiver.name()] // likewise ^^^^^^^^^^^^^^^^^^^^^^ References: - ex_special_cases.js:38:26 - 38| declare var array: Array; + ex_special_cases.js:35:26 + 35| declare var array: Array; ^^^^^^ [1] - ex_special_cases.js:40:12 - 40| var test2: string = array[receiver.name()] // likewise + ex_special_cases.js:37:12 + 37| var test2: string = array[receiver.name()] // likewise ^^^^^^ [2] diff --git a/tests/any/ex_special_cases.js b/tests/any/ex_special_cases.js index 42c0b3612c6..ac7daf2627b 100644 --- a/tests/any/ex_special_cases.js +++ b/tests/any/ex_special_cases.js @@ -3,8 +3,6 @@ // any ~> functionlike class C { } var C_any: any = C; -declare var cmp: $Compose; -var cmp_cany: any = cmp; declare var proto_apply: Function$Prototype$Apply; declare var proto_bind: Function$Prototype$Bind; declare var proto_call: Function$Prototype$Call; @@ -17,7 +15,6 @@ var f_any: any = f; // functionlike ~> any declare var a: any; var C_from_any: Class = a; -var cmp_from_any: $Compose = a; var proto_apply_from_any: Function$Prototype$Apply = a; var proto_bind_from_any: Function$Prototype$Bind = a; var proto_call_from_any: Function$Prototype$Call = a; diff --git a/tests/babel_loose_array_spread/babel_loose_array_spread.exp b/tests/babel_loose_array_spread/babel_loose_array_spread.exp index 6420620e464..a20ad7a18d1 100644 --- a/tests/babel_loose_array_spread/babel_loose_array_spread.exp +++ b/tests/babel_loose_array_spread/babel_loose_array_spread.exp @@ -20,34 +20,6 @@ References: ^ [2] -Error --------------------------------------------------------------------------------------------------- compose.js:6:2 - -A spread argument is unsupported here. [unsupported-syntax] - - v------- - 6| (compose( - 7| ...fns1, // Error - 8| )(42)); - ^ - - -Error --------------------------------------------------------------------------------------------------- compose.js:7:6 - -`$Iterable` [1] is incompatible with `$ReadOnlyArray` [2]. [incompatible-type] - - compose.js:7:6 - 7| ...fns1, // Error - ^^^^ - -References: - compose.js:4:19 - 4| declare var fns1: Iterable<(number) => number>; - ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ [1] - /core.js:698:15 - 698| declare class $ReadOnlyArray<+T> { - ^^^^^^^^^^^^^^ [2] - - Error ------------------------------------------------------------------------------------------------- iterables.js:2:5 `$Iterable` [1] is incompatible with `$ReadOnlyArray` [2]. [incompatible-type] @@ -219,4 +191,4 @@ References: -Found 13 errors +Found 11 errors diff --git a/tests/babel_loose_array_spread/compose.js b/tests/babel_loose_array_spread/compose.js deleted file mode 100644 index 62f94e085bc..00000000000 --- a/tests/babel_loose_array_spread/compose.js +++ /dev/null @@ -1,14 +0,0 @@ -/* @flow */ - -declare var compose: $Compose; -declare var fns1: Iterable<(number) => number>; - -(compose( - ...fns1, // Error -)(42)); - -if (Array.isArray(fns1)) { - (compose( - ...fns1, // No error - )(42)); -} diff --git a/tests/babel_loose_array_spread/passing_cases.js b/tests/babel_loose_array_spread/passing_cases.js index ebd56a2b603..05a0656cbc6 100644 --- a/tests/babel_loose_array_spread/passing_cases.js +++ b/tests/babel_loose_array_spread/passing_cases.js @@ -16,7 +16,10 @@ f.bind(null, ...b); function f(...args: Array) {} -declare var compose: $Compose; +declare function compose, R>( + f1: (a: A) => R, + f2: (...T) => A, +): (...T) => R; compose(...[(x: mixed) => x, (x: mixed) => x]); const c: $ReadOnlyArray = [4,5,6]; diff --git a/tests/compose/.flowconfig b/tests/compose/.flowconfig deleted file mode 100644 index bd307edb1c9..00000000000 --- a/tests/compose/.flowconfig +++ /dev/null @@ -1,7 +0,0 @@ -[libs] -lib/ - -[options] -all=true -exact_by_default=false -no_flowlib=false diff --git a/tests/compose/basic.js b/tests/compose/basic.js deleted file mode 100644 index 4e6a7448c8b..00000000000 --- a/tests/compose/basic.js +++ /dev/null @@ -1,16 +0,0 @@ -declare var compose: $Compose; -declare var composeReverse: $ComposeReverse; - -(compose((n: number) => n.toString())(42): empty); // Error: string ~> empty - -(composeReverse((n: number) => n.toString())(42): empty); // Error: string ~> empty - -(compose( - (n: number) => n * 5, // Error: string cannot be multiplied. - (n: number) => n.toString(), -)(42): empty); // Error: number ~> empty - -(composeReverse( - (n: number) => n * 5, // OK - (n: number) => n.toString(), -)(42): empty); // Error: string ~> empty diff --git a/tests/compose/compose.exp b/tests/compose/compose.exp deleted file mode 100644 index 110d0555e59..00000000000 --- a/tests/compose/compose.exp +++ /dev/null @@ -1,122 +0,0 @@ -Error ----------------------------------------------------------------------------------------------------- basic.js:4:2 - -Cannot cast `compose(...)(...)` to empty because string [1] is incompatible with empty [2]. [incompatible-cast] - - basic.js:4:2 - 4| (compose((n: number) => n.toString())(42): empty); // Error: string ~> empty - ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - -References: - /core.js:485:31 - 485| toString(radix?: number): string; - ^^^^^^ [1] - basic.js:4:44 - 4| (compose((n: number) => n.toString())(42): empty); // Error: string ~> empty - ^^^^^ [2] - - -Error ----------------------------------------------------------------------------------------------------- basic.js:6:2 - -Cannot cast `composeReverse(...)(...)` to empty because string [1] is incompatible with empty [2]. [incompatible-cast] - - basic.js:6:2 - 6| (composeReverse((n: number) => n.toString())(42): empty); // Error: string ~> empty - ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - -References: - /core.js:485:31 - 485| toString(radix?: number): string; - ^^^^^^ [1] - basic.js:6:51 - 6| (composeReverse((n: number) => n.toString())(42): empty); // Error: string ~> empty - ^^^^^ [2] - - -Error ----------------------------------------------------------------------------------------------------- basic.js:8:2 - -Cannot cast `compose(...)(...)` to empty because number [1] is incompatible with empty [2]. [incompatible-cast] - - basic.js:8:2 - v------- - 8| (compose( - 9| (n: number) => n * 5, // Error: string cannot be multiplied. - 10| (n: number) => n.toString(), - 11| )(42): empty); // Error: number ~> empty - ----^ - -References: - basic.js:9:18 - 9| (n: number) => n * 5, // Error: string cannot be multiplied. - ^^^^^ [1] - basic.js:11:8 - 11| )(42): empty); // Error: number ~> empty - ^^^^^ [2] - - -Error ----------------------------------------------------------------------------------------------------- basic.js:9:3 - -Cannot call `compose` with compose intermediate value bound to `n` because string [1] is incompatible with number [2]. -[incompatible-call] - - basic.js:9:3 - 9| (n: number) => n * 5, // Error: string cannot be multiplied. - ^^^^^^^^^^^^^^^^^^^^ - -References: - /core.js:485:31 - 485| toString(radix?: number): string; - ^^^^^^ [1] - basic.js:9:7 - 9| (n: number) => n * 5, // Error: string cannot be multiplied. - ^^^^^^ [2] - - -Error ---------------------------------------------------------------------------------------------------- basic.js:13:2 - -Cannot cast `composeReverse(...)(...)` to empty because string [1] is incompatible with empty [2]. [incompatible-cast] - - basic.js:13:2 - v-------------- - 13| (composeReverse( - 14| (n: number) => n * 5, // OK - 15| (n: number) => n.toString(), - 16| )(42): empty); // Error: string ~> empty - ----^ - -References: - /core.js:485:31 - 485| toString(radix?: number): string; - ^^^^^^ [1] - basic.js:16:8 - 16| )(42): empty); // Error: string ~> empty - ^^^^^ [2] - - -Error ----------------------------------------------------------------------------------------------- recompose.js:23:19 - -Cannot call `Math.round` with `props.p` bound to `x` because string [1] is incompatible with number [2]. -[incompatible-call] - - recompose.js:23:19 - 23| c: Math.round(props.p), // Error: string ~> number - ^^^^^^^ - -References: - recompose.js:22:27 - 22| myEnhancer((props: {|p: string|}) => ({ - ^^^^^^ [1] - /core.js:655:14 - 655| round(x: number): number, - ^^^^^^ [2] - - -Error ---------------------------------------------------------------------------------------------------- spread.js:4:2 - -A spread argument is unsupported here. [unsupported-syntax] - - 4| (compose(...fns)(42): empty); // Error: unsupported - ^^^^^^^^^^^^^^^ - - - -Found 7 errors diff --git a/tests/compose/lib/recompose.js b/tests/compose/lib/recompose.js deleted file mode 100644 index 4b8a235711d..00000000000 --- a/tests/compose/lib/recompose.js +++ /dev/null @@ -1,3 +0,0 @@ -declare module 'recompose' { - declare export var compose: $Compose; -} diff --git a/tests/compose/recompose.js b/tests/compose/recompose.js deleted file mode 100644 index 92130e39ff4..00000000000 --- a/tests/compose/recompose.js +++ /dev/null @@ -1,25 +0,0 @@ -/** - * @flow - * - * This test was taken from: - * https://github.com/istarkov/flow-compose-error - */ - -import { compose } from 'recompose'; - -// shared code between bad/good Compose -type Comp = (a: A) => void; -type HOC = (a: Comp) => Comp; - -function myEnhancer(mapper: B => A): HOC { - return (comp: Comp) => (props: B) => comp(mapper(props)); -} - -const enhancer: HOC = compose( - myEnhancer((props: {e: string, p: number, ...}) => ({ - p: `${props.p * 3}`, - })), - myEnhancer((props: {|p: string|}) => ({ - c: Math.round(props.p), // Error: string ~> number - })) -); diff --git a/tests/compose/spread.js b/tests/compose/spread.js deleted file mode 100644 index 22c8ee56b3d..00000000000 --- a/tests/compose/spread.js +++ /dev/null @@ -1,4 +0,0 @@ -declare var compose: $Compose; -declare var fns: Array<(number) => number>; - -(compose(...fns)(42): empty); // Error: unsupported diff --git a/tests/react_hocs/hocs.js b/tests/react_hocs/hocs.js index fad51dbcb1d..a827ec0e494 100644 --- a/tests/react_hocs/hocs.js +++ b/tests/react_hocs/hocs.js @@ -1,6 +1,9 @@ import * as React from 'react'; -declare export var compose: $Compose; +declare export function compose( + f1: (a: A) => R, + f2: (b: B) => A, +): (B) => R; export function mapProps( mapperFn: (InputProps) => OutputProps, @@ -14,6 +17,5 @@ export function withProps( ...Props, ...ExtraProps, |}>) => React.ComponentType { - // $FlowFixMe: This will be ok when we have value spread. return Component => props => ; } diff --git a/tests/react_hocs/react_hocs.exp b/tests/react_hocs/react_hocs.exp index e8aca124c2f..9008d408590 100644 --- a/tests/react_hocs/react_hocs.exp +++ b/tests/react_hocs/react_hocs.exp @@ -25,12 +25,12 @@ exists in `Props` [2]. [prop-missing] ^^^ References: - hocs.js:13:25 + hocs.js:16:25 v- - 13| ): (React.ComponentType<{| - 14| ...Props, - 15| ...ExtraProps, - 16| |}>) => React.ComponentType { + 16| ): (React.ComponentType<{| + 17| ...Props, + 18| ...ExtraProps, + 19| |}>) => React.ComponentType { -^ [1] Bad.js:9:21 9| const Bad = (props: Props) => null;