Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Arguments appears to be lossy when using spread syntax #19

Open
magicmark opened this issue Sep 9, 2019 · 3 comments
Open

Arguments appears to be lossy when using spread syntax #19

magicmark opened this issue Sep 9, 2019 · 3 comments

Comments

@magicmark
Copy link

magicmark commented Sep 9, 2019

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!

@magicmark
Copy link
Author

magicmark commented Sep 9, 2019

Paring it back a bit more:

type GetUserInfoArgs = {| user_id: number |};
type GetUserInfo = (GetUserInfoArgs) => { first_name: string, last_name: string };

// Similar to how `Arguments` works - produces the same error
type ExtractArg = <A, F: (A) => any>(F) => A & A
type DerivedArg = $Call<ExtractArg, GetUserInfo>

/**
 * 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' };

@magicmark
Copy link
Author

Hmm, related? facebook/flow#7709

@lttb
Copy link
Owner

lttb commented Sep 9, 2019

Hi @magicmark, thank you very much for the issue!

I'll try to check it asap, I hope to have a chance to look at this tomorrow

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants