-
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
Please revert the JSON.stringify definition patch(es) #7565
Comments
Unlike what the announcement says, the new definitions do not disallow functions. Codefunction getData() {};
JSON.stringify(getData); Result
|
Some other weird examples: and especially this: Maybe I don't understand something, but especially in the last example there shouldn't be possibility to pass any nullish values in? |
@villesau Your first example gives no definition of I just had some issues with Flow-Try links showing different code depending on where I open them though so I'm not sure I see what you see. Weird, the incognito window shows different code then the regular one, for the exact same link. EDIT: After clearing all site data for Flow-Try it seems to work. I see as your 2nd example this: /* @flow */
function foo(x: ?number): string {
if (x) {
return x;
}
return "default string";
} which Flow rightly complains about and which does not have any |
Looks like the URL of the second example is malformed and shows your previous flow example. Dunno why. This is what it was supposed to be: https://flow.org/try/#0PTAEAEDMBsHsHcBQBjWA7AzgF1AEwKaQCGArtFgLJFbIAWAklvgLagC8oAPIywCoCeAB3wA+ABQBLJswBcoHswHCANKAz4iAJzoAFak01o52TRLQBzAJTsRiUKABSAZQDyAOQB0Js+YmR+ktKgAD7BAAUA5BGWHmYEAB4ukGLqWrr6+IbWAIRsHAC0AIwA3EA E: This is what it's supposed to be:
|
@villesau That's the first example, but now with an additional |
Yeah. And I believe that |
Please revert the
|
The original definition (pre-0.95) was unsound, because Flow would assign This new libdef is a step towards soundness, and while I recognize that it can be inconvenient at times for the type system to be conservative like this, I believe it is the right direction for us to move in. I think it's also worth noting that the original PR got several people interested enough to comment, the original thread on Twitter got several other people interested, and it looks like TypeScript intends to merge an equivalent PR: microsoft/TypeScript#29744. There may be room for improvement in the libdef, and I'd be happy to review PRs which improve usability without sacrificing soundness. However, I don't currently believe that reverting is the right decision. As you noted, it still allows functions to be passed in, which isn't desirable. I also noted this in the tests. This is unfortunate but at this point I believe there is little we can do about it. |
@nmote I know it was unsound, that is reflected in the comments I quoted. Did you read them? If you did you ignored them. The current state is against the very principles laid out right there! If it's not representable by Flow — as is a lot of other stuff! — than one has to compromise. As happens all the time, right here. This is a strange hill that you chose to make your stand on, a lonely hill (the circumstances that cause a Of what use is your "soundness" if you force people to overwrite that definition? Or do you think people will add lots and lots of utterly useless checks for undefined for every |
@lll000111 you seem to be upset that Flow is "always" returning undefined:
but that's not true:
Even your Flow returns There are also cases where it may actually return undefined at runtime, but we still unsoundly say it'll be a string, like when you pass something we know is a function (your |
EDIT See summary comment below: #7565 (comment) This issue here just illustrates an aspect of the larger point made there.
Flow version: 0.95,1
Flow Try link
It's "correct" because according to the new definition the return value could always be
undefined
, regardless of input parameter(s). This is what the change to the definition tried to get rid of — but it never was a problem until the change....Code
Result
The text was updated successfully, but these errors were encountered: