-
Notifications
You must be signed in to change notification settings - Fork 22.5k
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
Clarify that Location.assign
and Location.replace
also accept URL
s
#36432
Conversation
Preview URLs (comment last updated: 2024-10-26 18:33:22) |
There's nothing special about passing URLs to these APIs. They merely coerce everything to strings. Check the spec: https://html.spec.whatwg.org/multipage/nav-history-apis.html#the-location-interface The reason TypeScript needs to declare the type like this is because it doesn't have a type that means "all objects with sensible |
Saying it accepts "a string" is still incorrect, thought. Maybe it should say "a string, or any object with a |
I think we have precedents of doing similar stuff elsewhere, so you may want to search for one, but the idea makes sense to me. |
Yeah, for one relevant precedent, see the wording about the
And in that same article, see the note at https://developer.mozilla.org/en-US/docs/Web/API/URL/URL#sect2:
|
I agree and have changed to use the form "'A string or any other object with a stringifier'" of that wording now. |
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Description
Location.assign
andLocation.replace
also acceptURL
sMotivation
This works in all browsers I tested (Firefox, Chrome, Safari, PaleMoon), so MDN was incorrect.
Additional details
TypeScript has it correct already:
https://github.com/microsoft/TypeScript/blob/e6ef279403d86440600c866d53839a3e695220d3/src/lib/dom.generated.d.ts#L15107
https://github.com/microsoft/TypeScript/blob/e6ef279403d86440600c866d53839a3e695220d3/src/lib/dom.generated.d.ts#L15119