Skip to content
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

Closed
wants to merge 2 commits into from
Closed

Added the fetch api #12493

wants to merge 2 commits into from

Conversation

RobinVdBroeck
Copy link

Fixes #4948
I didn't know how to write unit tests for it since its actually a library change.

@msftclas
Copy link

Hi @GamesMaxed, I'm your friendly neighborhood Microsoft Pull Request Bot (You can call me MSBOT). Thanks for your contribution!
You've already signed the contribution license agreement. Thanks!
We will now validate the agreement and then real humans will evaluate your PR.

TTYL, MSBOT;

}
declare var fetch: typeof window.fetch;

declare type HeadersInit = Headers | string[][] | { [key: string]: string };

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]> :/

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1

Copy link
Contributor

@mohsen1 mohsen1 Jan 1, 2017

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' //...

@ctaggart
Copy link
Contributor

ctaggart commented Dec 12, 2016

I used this for a basic request and blogged about it here:
http://blog.ctaggart.com/2016/12/fetch-api-via-typescript-async.html

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"]
Copy link
Contributor

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.

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...

Copy link
Contributor

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"]
Copy link
Contributor

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>
Copy link
Contributor

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" />
Copy link
Contributor

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

Copy link
Contributor

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 };
Copy link
Contributor

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;
Copy link
Contributor

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>;
Copy link
Contributor

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;
Copy link
Contributor

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>;
Copy link
Contributor

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) }
Copy link
Contributor

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 {
Copy link
Member

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?

Copy link
Contributor

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; 🌹

Copy link
Contributor

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.

@basarat basarat mentioned this pull request Dec 31, 2016
@RyanLamansky
Copy link

Has this PR been abandoned? I'd love to see this get merged in after the concerns are addressed...

@RobinVdBroeck
Copy link
Author

RobinVdBroeck commented Feb 9, 2017

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?

@remojansen
Copy link
Contributor

@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.

@mhegazy
Copy link
Contributor

mhegazy commented Feb 9, 2017

The fetch API should be in the standard library after #13856

@mhegazy mhegazy closed this Feb 9, 2017
@microsoft microsoft locked and limited conversation to collaborators Jun 19, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

10 participants