-
Notifications
You must be signed in to change notification settings - Fork 9.1k
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
fix: type page event listeners correctly #6891
Conversation
abefe64
to
8333d04
Compare
src/common/HTTPRequest.ts
Outdated
/** | ||
* Optional response headers. All values are converted to strings. | ||
*/ | ||
headers: Record<string, any>; |
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.
Why did you change this to any?
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.
Good point, not sure. I think we stringify them anyway so unknown
is better here.
requestfailed: HTTPRequest; | ||
requestfinished: HTTPRequest; | ||
workercreated: WebWorker; | ||
workerdestroyed: WebWorker; |
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.
What about adding a [event: string]: any at the bottom here to make sure we don't break places that use other event names? Or is that intended?
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'd rather it fail explicitly because we're missing a type.
This PR fixes the fact that currently if you have: ```ts page.on('request', request => { }) ``` Then `request` will be typed as `any`. We can fix this by defining an interface of event name => callback argument type, and looking that up when you call `page.on`. Also includes a drive-by fix to ensure we convert response headers to strings, and updates the types accordingly.
f2c26d3
to
2f69f52
Compare
This PR fixes the fact that currently if you have:
Then
request
will be typed asany
. We can fix this by defining aninterface of event name => callback argument type, and looking that up
when you call
page.on
.Fixes #6854.