-
Notifications
You must be signed in to change notification settings - Fork 12.7k
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
Added the fetch api #12493
Added the fetch api #12493
Conversation
Hi @GamesMaxed, I'm your friendly neighborhood Microsoft Pull Request Bot (You can call me MSBOT). Thanks for your contribution! TTYL, MSBOT; |
} | ||
declare var fetch: typeof window.fetch; | ||
|
||
declare type HeadersInit = Headers | string[][] | { [key: string]: string }; |
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.
Maybe ([string, string])[]
instead of string[][]
?
I also checked and was slightly disappointed to see it cannot accept arbitrary Iterable<[string, string]>
:/
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.
+1
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.
For autocomplete maybe we add list of known headers
type KnownHeaders = 'Accept' | 'Accept-Charset' //...
I used this for a basic request and blogged about it here: Looking forward to seeing this worked on and merged. Thanks for putting this together. |
@@ -137,13 +137,16 @@ const es2017LibrarySourceMap = es2017LibrarySource.map(function(source) { | |||
}); | |||
|
|||
const hostsLibrarySources = ["dom.generated.d.ts", "webworker.importscripts.d.ts", "scripthost.d.ts"]; | |||
const es2015HostLibrarySources = ["dom.iterable.d.ts", "streams.d.ts", "fetch.d.ts"] |
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 do not think this should be added to the es6 library. it is not related to the ES6 spec, it is an HTML standard.
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.
How should this be handled? dom.iterable.d.ts
would still have to depend on iterables, which will depend on ES6 Symbol
, which will depend on ES6 Object
...
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.
The file should have /// references on all parts of the es2015 it depends on.
@@ -312,13 +312,16 @@ var es2017LibrarySourceMap = es2017LibrarySource.map(function (source) { | |||
}); | |||
|
|||
var hostsLibrarySources = ["dom.generated.d.ts", "webworker.importscripts.d.ts", "scripthost.d.ts"]; | |||
var es2015HostLibrarySources = ["dom.iterable.d.ts", "streams.d.ts", "fetch.d.ts"] |
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.
same here.
@@ -0,0 +1,129 @@ | |||
/// The fetch API standard can be found at https://fetch.spec.whatwg.org/ | |||
/// Definitions by: Ryan Graham <https://github.com/ryan-codingintrigue>, Kagami Sascha Rosylight <https://github.com/saschanaz>, Robin Van den Broeck <https://github.com/gamesmaxed> |
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.
We have not included any similar headers in the other lib files. please remove that.
/// The fetch API standard can be found at https://fetch.spec.whatwg.org/ | ||
/// Definitions by: Ryan Graham <https://github.com/ryan-codingintrigue>, Kagami Sascha Rosylight <https://github.com/saschanaz>, Robin Van den Broeck <https://github.com/gamesmaxed> | ||
|
||
/// <reference path="lib.streams.d.ts" /> |
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.
also add a reference to lib.es2015.iterables
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.
and lib.es2015.promise
} | ||
declare var fetch: typeof window.fetch; | ||
|
||
declare type HeadersInit = Headers | string[][] | { [key: string]: string }; |
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.
+1
declare class WritableStream { | ||
constructor(underlyingSink?: WritableStreamSink, strategy?: QueuingStrategy); | ||
|
||
locked: boolean; |
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.
readonly
declare class WritableStreamDefaultWriter { | ||
constructor(stream: WritableStream); | ||
|
||
closed: 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.
readonly
constructor(stream: WritableStream); | ||
|
||
closed: Promise<void>; | ||
desiredSize: number; |
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.
readonly
|
||
closed: Promise<void>; | ||
desiredSize: number; | ||
ready: 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.
readonly
@@ -153,7 +156,7 @@ const librarySourceMap = [ | |||
|
|||
// JavaScript + all host library | |||
{ target: "lib.d.ts", sources: ["header.d.ts", "es5.d.ts"].concat(hostsLibrarySources) }, | |||
{ target: "lib.es6.d.ts", sources: ["header.d.ts", "es5.d.ts"].concat(es2015LibrarySources, hostsLibrarySources, "dom.iterable.d.ts") } | |||
{ target: "lib.es6.d.ts", sources: ["header.d.ts", "es5.d.ts"].concat(es2015LibrarySources, hostsLibrarySources, es2015HostLibrarySources) } |
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.
you also need to add entries in commandlineparser.ts for the two new lib targets.
|
||
/// <reference path="lib.streams.d.ts" /> | ||
|
||
interface Window { |
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 have always been curious why fetch has been under window - window.fetch()
. Why not just make it so that fetch()
works out of the box? Or might be could support both?
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.
@prabirshrestha also works without window
as #12493 (diff) has declare var fetch: typeof window.fetch;
🌹
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.
Yup, fetch should be available in non window contexts like Service Workers.
Has this PR been abandoned? I'd love to see this get merged in after the concerns are addressed... |
Sorry, I was busy in real life with exams and some private stuff and I totally forgot about this. What needs to be done now? Since this is one of my first PRs I'm not familiar with how the changes work? Do I need to pull them into my repo? What can I do now? |
@GamesMaxed just update your fork based on the comments and push to your fork again. The new commit will be built by CI. If the build has no errors and all the changes have been done they will merge your PR. |
The fetch API should be in the standard library after #13856 |
Fixes #4948
I didn't know how to write unit tests for it since its actually a library change.