Skip to content

type RequestInfo should include URL #1016

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

Closed
aslilac opened this issue Jun 3, 2021 · 7 comments · Fixed by #1269
Closed

type RequestInfo should include URL #1016

aslilac opened this issue Jun 3, 2021 · 7 comments · Fixed by #1269

Comments

@aslilac
Copy link

aslilac commented Jun 3, 2021

Currently RequestInfo is Request | string, but should (minimally) be Request | URL | string.

fetch(new URL('/some_api', 'https://example.com')) is valid, and works as you'd expect.

Technically it should be Request | { toString(): string } | string according to MDN, but I'm not sure if there are intricacies around that.

@Paril
Copy link

Paril commented Jun 5, 2021

I think the intricacy for the latter is that it's not very type-safe and more error-prone, since everything will toString to something, but it's often not what you expect it to be unless it's a primitive. They use the same thing for dataset/css style values, as well as other writeables, even if the spec allows and/or encourages it (for instance writing to window.location can be done with a string, and is most commonly done as such, but currently it's only writeable with a URL)

@aslilac
Copy link
Author

aslilac commented Jun 6, 2021

Yeah, it feels like { toString(): string } falls into the same pit as {} in that almost anything could be cast to it.

@orta
Copy link
Contributor

orta commented Jun 28, 2021

Agree, I think we probably don't want this

@orta
Copy link
Contributor

orta commented Jun 28, 2021

Related: #1003

@dnalborczyk
Copy link

dnalborczyk commented Oct 19, 2021

Agree, I think we probably don't want this

Actually I would think we do want this.

https://developer.mozilla.org/en-US/docs/Web/API/fetch#parameters

A string or any other object with a stringifier — including a URL object — that provides the URL of the resource you want to fetch.

@dnalborczyk
Copy link

speaking of which, this is pretty much the same problem, but has been added:

#331
#332

@dnalborczyk
Copy link

dnalborczyk commented Oct 19, 2021

as well as: #600

fetch falls pretty much into the same category.

similar: microsoft/TypeScript#43066

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

Successfully merging a pull request may close this issue.

4 participants