-
Notifications
You must be signed in to change notification settings - Fork 1.9k
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
$Diff with ...rest doesn't work #3541
Comments
Indeed, you can't use the spread type on a $Diff type either: type SpreadFromDiff = {...$Diff<Props, {title: string}>} |
$Diff is not a public feature. It only works properly as lower bound, i.e. you can assign something to it, but can't use it after that |
but the first example should work, right ? |
No, it shouldn't. $Diff only works properly as argument in declarations |
@vkurchatkin it's publicly documented https://flow.org/en/docs/types/utilities/#toc-diff and I don't see how that example is different from the example in this issues (sans the It would be great if you can provide an example of how it can be used since I've tried |
Edit |
Here is as simple example: type X = $Diff<{ a: string}, {}>;
var x: X = { a: 'string' }; // This works as expected
x.a; // This is an error Each type consists of two parts: upper bound and lower bound. Upper bound defines if you can assign something to the type (i.e. if it's a subtype of the type). Lower bound defines if you can use the type in some particular way. So if you want to use |
@vkurchatkin thanks for the example, that clears things up, really helpful! Just a detail, in the other post above you wrote "lower bound" and this reply "upper bound" (which matches your explanation for |
Issue described by @vkurchatkin above doesn't seem to be an issue any longer since flow 0.57 |
Example:
Gives an error:
However if i declare
WrapProps
sub type manually, it works:Seems like $Diff is not working correctly.
The text was updated successfully, but these errors were encountered: