flown
flown copied to clipboard
`Arguments` appears to be lossy when using spread syntax
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' };
Perhaps I'm missing something, but I'd expect flow to complain about b
?
Thanks!
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' };
Hmm, related? https://github.com/facebook/flow/issues/7709
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