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
Cannot use url.format with url.parse #908
Comments
So, this one is a bit tricky, unfortunately. There are two separate issues here: one that we can fix, and one that requires a bit more work. The issue that we can fix: the declared types of
While
However, we still get errors using this, although they are fewer:
These errors are more specific, and we can trace them down to the props which are different between
So this unification is tricky, because Flow is doing it for a good reason, which doesn't happen to apply in this case. Objects in JavaScript are mutable, so we can imagine many examples where this unification is necessary. /* @flow */
function foo(): { foo: string } {
return { foo: "foo" };
}
function bar(o: { foo?: string }): void {
delete o.foo;
}
var o: { foo: string } = foo();
bar(o);
o.foo.length; // BOOM What we need here is some way to declare that I hope this explanation was clear. Flow really, really needs const values for this kind of thing. I'm not sure anyone is working on it at the moment, but it's a well known issue to the team. Thanks for submitting this interesting issue! |
Summary: `url.format` could not consume the result from `url.parse`, since the two were inconsistent about whether they used optional or nullable properties. Improves the situation in #908 Reviewed By: mroch Differential Revision: D2681895 fb-gh-sync-id: 062ee06777980afda121a052d2b789033c1601f6
I am having a similar issue while trying to do the opposite: |
Workaround (kind of weird to accept this) parse(format({
href: baseUrl.href,
protocol: baseUrl.protocol,
slashes: baseUrl.slashes,
auth: baseUrl.auth,
hostname: baseUrl.hostname,
port: baseUrl.port,
host: baseUrl.host,
pathname: baseUrl.pathname,
search: baseUrl.search,
query: baseUrl.query,
hash: baseUrl.hash,
})) |
Using flow 0.16
I have no idea why this doesn't check (and why the error is so big); a parsed URL should be a valid parameter to
url.format
Sample program:
Output:
The text was updated successfully, but these errors were encountered: