-
Notifications
You must be signed in to change notification settings - Fork 166
Initialize JavaScript tests with polyfilled fetch #7518
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -5,6 +5,8 @@ interface FormStepsWaitElements { | |
| form: HTMLFormElement; | ||
| } | ||
|
|
||
| type FetchOrFetchPolyfill = typeof window.fetch & { polyfill?: boolean }; | ||
|
|
||
| interface FormStepsWaitOptions { | ||
| /** | ||
| * Poll interval. | ||
|
|
@@ -118,7 +120,7 @@ export class FormStepsWait { | |
| body: new window.FormData(form), | ||
| }); | ||
|
|
||
| if ('polyfill' in window.fetch) { | ||
| if ((window.fetch as FetchOrFetchPolyfill).polyfill) { | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Change from The polyfill sets it to
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. oh interesting. so if someone had
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah, the only way it could work previously is if we would delete the property altogether ( |
||
| // The fetch polyfill is implemented using XMLHttpRequest, which suffers from an issue where a | ||
| // Content-Type header from a POST is carried into a redirected GET, which is exactly the flow | ||
| // we are handling here. The current version of Rack neither handles nor provides easy insight | ||
|
|
||
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.
Jw: what is this syntax? merge of the surface of window.fetch with an additional flag?
Uh oh!
There was an error while loading. Please reload this page.
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, without this, TypeScript will become upset about trying to reference
fetch.polyfill, sincepolyfillis not a property on the default fetch implementation, only in the polyfill.So we typecast
fetchto a type which effectively extends the defaultfetchtype with the additional polyfill property.Specifically, the syntax is an intersection type: https://www.typescriptlang.org/docs/handbook/2/objects.html#intersection-types