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

Spreading $Shape of exact type is same as spreading of same exact type #6906

Closed
petejodo opened this issue Sep 19, 2018 · 6 comments
Closed

Comments

@petejodo
Copy link

It seems when spreading a $Shape of an exact type, it doesn't actually spread on type $Shape<T> but just spreads on T instead. The following breaks in try flow

type A = {| foo: number |};
type B = {| bar: string |};
type C<T, U> = {|
   ...T,
   ...$Shape<U>
|};

const c: C<A, B> = { // Error, property `bar` missing
  foo: 1
};
@orlandoc01
Copy link

Any updates on this issue? Is this a bug then in flow or are we misusing the spread operator with the $Shape type because we don' understand some behavior going on here?

@kvchen
Copy link

kvchen commented Jan 10, 2019

Shape doesn't behave quite as it states in the docs. To make all the keys optional, you can do something like this:

type Partial<T> = $Exact<{...{...T}}>;

Here's a link to Try Flow: https://flow.org/try/#0C4TwDgpgBACghgJ2ASzgGwDwBUB8UC8UAJAKIAecAxsBgN4B0jDjWAvqzgNwBQ3okUAIIEotAD5QAZgHtpALigA7AK4BbAEYQEUMax79oAIRHio6xAoDOwBMkUBzHXr7hoAYWwAaKAFU8hcW4oYMZ6LE8gkMZ4JFRMP25dHm5KaUVrKEoFD0FvQ39RSJl5KABGCODzAC8FABZuPSA

@orlandoc01
Copy link

Ok, I've been using the following instead actually:

type Partial<T> = $Rest<T, {}>;

https://flow.org/try/#0C4TwDgpgBACghgJ2ASzgGwDwBUB8UC8UAJAEoQDOw2ANFAN4C+OA3AFCuiRQCCB9APlABmAexEAuKADsArgFsARhARR+DNp2gAhPnUELEkygmRSA5qvUdw0AMI0oAVTyE9rKB4B03rNXdfveCRUTGdWNTZWAGMRKUooKMl7blotF3p-UQkoAEY-dSA

gnprice added a commit to gnprice/zulip-mobile that referenced this issue Apr 4, 2019
Thanks to facebook/flow#6906 for this `Partial` type -- a workaround
for `$Shape` not working correctly.

See also facebook/flow#7298.
gnprice added a commit to gnprice/zulip-mobile that referenced this issue Apr 5, 2019
Thanks to facebook/flow#6906 for this `Partial` type -- a workaround
for `$Shape` not working correctly.

See also facebook/flow#7298.
@goodmind goodmind added this to the New Object Spread semantics milestone Jul 17, 2019
@kevinbarabash
Copy link

Would it make sense to define $Shape's as $Rest<T, {}>? Are there things that rely on $Shape's behavior that wouldn't work this change?

gnprice added a commit to gnprice/zulip-mobile that referenced this issue Oct 17, 2019
Thanks to facebook/flow#6906 for this `Partial` type -- a workaround
for `$Shape` not working correctly.

See also facebook/flow#7298.
@somewhatabstract
Copy link

Now that https://github.com/facebook/flow/releases/tag/v0.162.0 includes $Partial, is this issue addressed?

@mrtnzlml
Copy link
Contributor

Now that https://github.com/facebook/flow/releases/tag/v0.162.0 includes $Partial, is this issue addressed?

It seems like yes: flow.org/try

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

No branches or pull requests

7 participants