-
Notifications
You must be signed in to change notification settings - Fork 440
Add URL to RequestInfo typedef #1269
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
Conversation
Thanks for the PR! This section of the codebase is owned by @saschanaz - if they write a comment saying "LGTM" then it will be merged. |
This sounds fair, but I wonder this could be breaking as some other libraries may be using |
Yeah, I trust past me to have done enough checking to make the call that we shouldn't do this last year, #1016 (comment) (likely because of ecosystem breakage) and I don't think anything's changed sinced then |
Please clarify: you're against allowing any random objects like |
Accepting URL for Web APIs is okay, what's not okay is to change the typedef and thus affect third-parties. I think changing the signatures of the APIs using |
src/build/emitter.ts
Outdated
if (p.name.toLowerCase().includes("url") && p.type === "USVString") { | ||
if ( | ||
(p.name.toLowerCase().includes("url") && p.type === "USVString") || | ||
p.type === "RequestInfo" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is now a little bit long to be in a if clause, could you add a function for this and call it here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good. Orta, wdyt?
(I'd prefer something like acceptsUrl
btw)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, I agree, this is a good solution - good creative thinking folks
@@ -3232,13 +3232,13 @@ declare var CSSTransition: { | |||
* Available only in secure contexts. | |||
*/ | |||
interface Cache { | |||
add(request: RequestInfo): Promise<void>; | |||
add(request: RequestInfo | URL): Promise<void>; | |||
addAll(requests: RequestInfo[]): Promise<void>; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure how to treat this one 🤔 but okay for now.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure how to properly implement this in generator either.
But in my opinion, even something like RequestInfo[] | URL[]
would be an okay trade-off here: mixing those in userland code should be rarely needed.
Another option is to refactor this later by introducing some urlstring
and RequestInfoOrUrl
typedefs. Dunno about downsides.
These should be affected as well:
TypeScript-DOM-lib-generator/baselines/dom.iterable.generated.d.ts
Lines 25 to 27 in d060ef5
interface Cache { | |
addAll(requests: Iterable<RequestInfo>): Promise<void>; | |
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmmmmmm. Let's merge this and tackle this in a separate patch.
lgtm |
Merging because @saschanaz is a code-owner of all the changes - thanks! |
Fixes: #1016
In most methods urlstring params are declared as
string | URL
, which ensures perfect balance between safe code and implicit casts allowed forUSVString
.This PR aligns
RequestInfo
with them.In particular, it allows to pass
URL
objects infetch
.