flow icon indicating copy to clipboard operation
flow copied to clipboard

FLOW BUG: This is a misplaced error

Open ayroblu opened this issue 2 years ago • 3 comments

Flow version: 0.226.0

On upgrading to 0.226, I get this error:

Cannot instantiate Connector because Arg3 [1] is underconstrained by BindActionCreatorObject [2]. Either add explicit
type arguments or cast the expression to your expected type. (FLOW BUG: This is a misplaced error. The original error
was raised in file app/components/FollowHostButton.js).
[underconstrained-implicit-instantiation]

     app/components/Component/connect.js
      22|     FOLLOW_BUTTON_CONTEXT
      23|   ),
      24|   follow: users.follow,
      25| })): Connector<FollowButtonProps, {||}, Actions>);
      26|

     app/redux/connect.js
 [1]  46|   <Arg1, Arg2, Arg3, Action>(
        :
 [2] 124| export type BindActionCreatorObject<ActionCreators: {}> = $ObjMap<
     125|   ActionCreators,
     126|   BindActionCreator
     127| >;

I'm specifically calling out the "FLOW BUG", which is confusing. Is this error correct? If I open in VS Code it flashes briefly with the underline, but then doesn't show the error.

ayroblu avatar Feb 15 '24 10:02 ayroblu

Can you try replacing your $ObjMap with mapped types? https://flow.org/en/docs/types/mapped-types/

gkz avatar Feb 16 '24 00:02 gkz

The error is correct, the BUG refers to the fact that the error is misplaced: it's raised as a result of checking file a but raised in file b. Our LSP implementation assumes this doesn't happen, so it results in confusing experience in your IDE. If you want help fixing the error, you will need to include more context.

SamChou19815 avatar Feb 16 '24 01:02 SamChou19815

I see. I can try to migrate to mapped types.

However, this syntax works in TypeScript playground but doesn't work in Flow playground Please let me know if there's a better syntax for it:

declare function f(s: string, n?: number): boolean;
type Tuple = Parameters<typeof f>;
declare function g(...args: Parameters<typeof f>): boolean;
g("hi")

ayroblu avatar Feb 16 '24 01:02 ayroblu