Skip to content

Weird post-hoc inferrence in function types generated from $Call? #8838

@tolmasky

Description

@tolmasky

Flow version: 0.171.0

Expected behavior

I'd expect both of these snippets of code to generate the same error, but only the normal generic errors, the $Call generated one does not:

type ToFunction<Parameter> = (x: Parameter) => string;
declare var expectString : ToFunction<string>;

expectString(10); // Correctly gives me an error
 
type _ToFunctionFromCall = <Parameter> (Parameter) => (x: Parameter) => string;
type ToFunctionFromCall<Parameter> = $Call<_ToFunctionFromCall, string>;

declare var expectStringFromCall : ToFunctionFromCall<string>;

// Does not give me an error, instead changes type of `expectStringFromCall`
// to (string | number) => string;
expectStringFromCall(10); 

I need the call version because I am passing it to $ObjMap. Currently, the $ObjMap appears like it's working, as hovering over the resultant types shows me what I expect to see ({ a: number => string, b: boolean => string, etc. }). Yet the second I try to use any of them, it just changes their parameter types to accept anything I pass to them.

Try in Flow

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions