Skip to content

Arguments appears to be lossy when using spread syntax #19

@magicmark

Description

@magicmark

First of - thanks @lttb so much for this library! It's a huge help!

I'm running into the following issue best demonstrated by a small repro:

type GetUserInfoArgs = {| user_id: number |};
type GetUserInfo = (GetUserInfoArgs) => { first_name: string, last_name: string };
type DerivedArg = $ElementType<Arguments<GetUserInfo>, 0>; // should be equivalent to `GetUserInfoArgs`?

/**
 * Using Arguments<GetUserInfo>:
 * - `a` fails type checking as expected
 * - `b` does not fail type checking :( 
 */
const a: DerivedArg = { foo: 'bar' };
const b: {| ...DerivedArg |} = { foo: 'bar' };

/**
 * Without using Arguments<GetUserInfo>:
 * - `c` fails type checking as expected
 * - `d` fails type checking as expected 
 */
const c: GetUserInfoArgs = { foo: 'bar' };
const d: {| ...GetUserInfoArgs |} = { foo: 'bar' };

Link to full repro in tryflow

Perhaps I'm missing something, but I'd expect flow to complain about b?

Thanks!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions