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

Fetch API definitions #4948

Closed
myitcv opened this issue Sep 24, 2015 · 29 comments
Closed

Fetch API definitions #4948

myitcv opened this issue Sep 24, 2015 · 29 comments
Labels
Domain: lib.d.ts The issue relates to the different libraries shipped with TypeScript Help Wanted You can do this

Comments

@myitcv
Copy link

myitcv commented Sep 24, 2015

Apologies if this is mentioned elsewhere, but I couldn't find an issue/PR that mentions it.

The Fetch API is still experimental, but I assume its definitions will make their way into TypeScript core at some point?

@myitcv
Copy link
Author

myitcv commented Sep 24, 2015

Reference the current DefinitelyTyped definitions.

@danquirk
Copy link
Member

Yes, when an API is standardized/well supported we'll make sure it's in lib.d.ts (or whatever appropriate sub component). We generally generate these libraries from spec's so we don't need issues per new API. In the meantime if you're hoping for improvements to the DefinitelyTyped definitions that's something we should track with an issue over there.

@danquirk danquirk added the Question An issue which isn't directly actionable in code label Sep 24, 2015
@myitcv
Copy link
Author

myitcv commented Sep 24, 2015

@danquirk - thanks, we're raising a PR to fix up one deviation from the spec.

@ghost
Copy link

ghost commented Aug 15, 2016

Still not supported ?

@heruan
Copy link

heruan commented Oct 18, 2016

Now that libs are split into multiple includable files, I think the fetch definition should be added in one of those lib files or in its own one.

@ghost ghost reopened this Oct 18, 2016
@mhegazy mhegazy removed the Question An issue which isn't directly actionable in code label Oct 19, 2016
@mhegazy
Copy link
Contributor

mhegazy commented Oct 19, 2016

PRs welcomed. You can find more information about contributing lib.d.ts fixes at https://github.com/Microsoft/TypeScript/blob/master/CONTRIBUTING.md#contributing-libdts-fixes.

@mhegazy mhegazy added Suggestion An idea for TypeScript Help Wanted You can do this Domain: lib.d.ts The issue relates to the different libraries shipped with TypeScript labels Oct 19, 2016
@mhegazy mhegazy added this to the Community milestone Oct 19, 2016
@ghost
Copy link

ghost commented Oct 21, 2016

There are already typings for it on DefinitelyTyped. Hopefully those could be moved to lib, then we could deprecate the @types/whatwg-fetch package. It apparently depends on whatwg-streams, so it's likely best to do these both together.

@mohsen1
Copy link
Contributor

mohsen1 commented Nov 3, 2016

All of Web IDL definitions are here:
https://src.chromium.org/viewvc/blink/trunk/Source/modules/fetch/

There is also this tool for converting Web IDL to TSD files: https://github.com/RicoP/idl2typings

Anyone wants to actually do it?

@mhegazy
Copy link
Contributor

mhegazy commented Nov 3, 2016

Be the PR you want to see in the world :)

@quantuminformation
Copy link

The PR would just be to add the fetch typings to lib.d.ts right?

@basarat
Copy link
Contributor

basarat commented Dec 31, 2016

@quantuminformation pr already at #12493 🌹

@quantuminformation
Copy link

@basarat roger that!

@mhegazy mhegazy modified the milestones: TypeScript 2.2.1, Community Feb 9, 2017
@mhegazy mhegazy added the Fixed A PR has been merged for this issue label Feb 9, 2017
@mhegazy
Copy link
Contributor

mhegazy commented Feb 9, 2017

This should be fixed by #13856

@mhegazy mhegazy closed this as completed Feb 9, 2017
@styfle
Copy link
Contributor

styfle commented Feb 9, 2017

@mhegazy Which version of TS is this expected to land in? And is there anything special to do in tsconfig.json to enable the fetch definitions?

@mhegazy
Copy link
Contributor

mhegazy commented Feb 9, 2017

As noted in the milestone, typescript@2.2.1

@jamir0
Copy link

jamir0 commented Feb 10, 2017

Hi, im not pretty sure what im' writing in correct topic, but i guess i have related issue.
in project i use several libs which in dependencies have isomorphic-fetch & whatwg-fetch. after update to typescript@>=2.1.5 i recieve errors:

Error - typescript - node_modules\@types\isomorphic-fetch\index.d.ts(6,14): error TS2300: Duplicate identifier 'RequestContext'.
Error - typescript - node_modules\@types\isomorphic-fetch\index.d.ts(14,14): error TS2300: Duplicate identifier 'RequestMode'.
Error - typescript - node_modules\@types\isomorphic-fetch\index.d.ts(15,14): error TS2300: Duplicate identifier 'RequestCredentials'.
Error - typescript - node_modules\@types\isomorphic-fetch\index.d.ts(16,14): error TS2300: Duplicate identifier 'RequestCache'.
Error - typescript - node_modules\@types\isomorphic-fetch\index.d.ts(20,14): error TS2300: Duplicate identifier 'ResponseType'.
Error - typescript - node_modules\@types\isomorphic-fetch\index.d.ts(22,14): error TS2300: Duplicate identifier 'HeaderInit'.
Error - typescript - node_modules\@types\isomorphic-fetch\index.d.ts(23,14): error TS2300: Duplicate identifier 'BodyInit'.
Error - typescript - node_modules\@types\isomorphic-fetch\index.d.ts(24,14): error TS2300: Duplicate identifier 'RequestInfo'.
Error - typescript - node_modules\@types\isomorphic-fetch\index.d.ts(41,15): error TS2300: Duplicate identifier 'Headers'.
Error - typescript - node_modules\@types\isomorphic-fetch\index.d.ts(60,15): error TS2300: Duplicate identifier 'Body'.
Error - typescript - node_modules\@types\isomorphic-fetch\index.d.ts(81,15): error TS2300: Duplicate identifier 'Request'.
Error - typescript - node_modules\@types\isomorphic-fetch\index.d.ts(115,13): error TS2300: Duplicate identifier 'fetch'.
Error - typescript - node_modules\@types\whatwg-fetch\index.d.ts(6,15): error TS2300: Duplicate identifier 'Request'.
Error - typescript - node_modules\@types\whatwg-fetch\index.d.ts(29,6): error TS2300: Duplicate identifier 'RequestContext'.
Error - typescript - node_modules\@types\whatwg-fetch\index.d.ts(37,6): error TS2300: Duplicate identifier 'RequestMode'.
Error - typescript - node_modules\@types\whatwg-fetch\index.d.ts(39,6): error TS2300: Duplicate identifier 'RequestCredentials'.
Error - typescript - node_modules\@types\whatwg-fetch\index.d.ts(40,6): error TS2300: Duplicate identifier 'RequestCache'.
Error - typescript - node_modules\@types\whatwg-fetch\index.d.ts(48,15): error TS2300: Duplicate identifier 'Headers'.
Error - typescript - node_modules\@types\whatwg-fetch\index.d.ts(59,15): error TS2300: Duplicate identifier 'Body'.
Error - typescript - node_modules\@types\whatwg-fetch\index.d.ts(69,15): error TS2300: Duplicate identifier 'Response'.
Error - typescript - node_modules\@types\whatwg-fetch\index.d.ts(82,6): error TS2300: Duplicate identifier 'ResponseType'.
Error - typescript - node_modules\@types\whatwg-fetch\index.d.ts(90,14): error TS2300: Duplicate identifier 'HeaderInit'.
Error - typescript - node_modules\@types\whatwg-fetch\index.d.ts(91,14): error TS2300: Duplicate identifier 'BodyInit'.
Error - typescript - node_modules\@types\whatwg-fetch\index.d.ts(92,14): error TS2300: Duplicate identifier 'RequestInfo'.
Error - typescript - node_modules\@types\whatwg-fetch\index.d.ts(98,13): error TS2300: Duplicate identifier 'fetch'.

i can't remove one of such definitions because they are dependencies from third part packages and they are installed (@types/isomorphic-fetch, @types/whatwg-fetch) own td's.

ps. i used some packages from MS to create webparts with react and apollo-client to connect to graphql.

Please does anyone know how to resolve this conflict?

@mhegazy
Copy link
Contributor

mhegazy commented Feb 11, 2017

@types/isomorphic-fetch is not authored correctly, (i.e. it puts declarations in the global scope, hence the duplicate declaration errors) this we can fix.

@types/whatwg-fetch has to be removed if you are using TS 2.2. Seems that the other @types package that depend on it is @type/service_worker_api and that would not be needed any longer.

If there are other dependencies, then you need them to publish a new version before using TS 2.2

@jamir0
Copy link

jamir0 commented Feb 14, 2017

All this errors were appeared after install npm install apollo-client react-apollo graphql-tag --save

@mhegazy
Copy link
Contributor

mhegazy commented Feb 14, 2017

All this errors were appeared after install npm install apollo-client react-apollo graphql-tag --save

we need to fix isomorphic-fetch first, then ask apollo-client to update their package.

@styfle
Copy link
Contributor

styfle commented Feb 14, 2017

@mhegazy I don't see an mention of lib.d.ts being updated in the Breaking Changes doc. Can you add it and explain what you wrote above (existing projects using fetch.d.ts, etc will need to remove it).

@mhegazy
Copy link
Contributor

mhegazy commented Feb 14, 2017

@mhegazy I don't see an mention of lib.d.ts being updated in documented in the Breaking Changes doc. Can you add it and explain what you wrote above (existing projects using fetch.d.ts, etc will need to remove it).

Yes. i have not fully updated the docs for the release yet. hopefully will do this this week. I still need to add the breaking changes, finish the what's new, and clean up the roadmap :)

@mhegazy
Copy link
Contributor

mhegazy commented Feb 18, 2017

Documentation added to breaking changes page: https://github.com/Microsoft/TypeScript/wiki/Breaking-Changes#changes-to-dom-apis-in-the-standard-library

@vladima vladima removed Fixed A PR has been merged for this issue Suggestion An idea for TypeScript labels Feb 18, 2017
@atrauzzi
Copy link

@mhegazy - Sorry, just to be clear -- if I'm working on a nodejs app, do I still need any kind of fetch polyfill, or does TypeScript provide it regardless of environment?

What are the correct steps in every scenario and do I still need any third party libraries, or is TypeScript fixing fetch "once and for all"??

@mhegazy
Copy link
Contributor

mhegazy commented Feb 21, 2017

@mhegazy - Sorry, just to be clear -- if I'm working on a nodejs app, do I still need any kind of fetch polyfill, or does TypeScript provide it regardless of environment?

The fetch API is included as part of the DOM API, so it is part of lib.dom.d.ts.

If you are using node, you are not interested in the DOM, so my recommendation is to use --lib es6 to get the core ES6 lib without the DOM. in this case you would not get the Fetch API. The correct thing to do here is to add that to @types/node

@styfle
Copy link
Contributor

styfle commented Feb 22, 2017

@atrauzzi These are typings only, there is no polyfill included for fetch just like there is no polyfill included for Promise.

There are very few polyfills included with typescript: class extends and async/await are really the only two I can think of. I suspect we won't see many more polyfills included in the future.

@jaredmahan
Copy link

So when are we expecting @types/isomorphic-fetch to be patched to work with the new typings?

@ghost
Copy link

ghost commented Feb 23, 2017

@mhegazy
Copy link
Contributor

mhegazy commented Feb 23, 2017

@types/isomorphic-fetch@0.0.33 should have the fix.

@emirotin
Copy link

emirotin commented Feb 25, 2017

It would be nice if the updated typings have kept the parity with the whatwg-fetch types.

Specifically the typed version of Body#json<T>() would be nice to have: https://github.com/DefinitelyTyped/DefinitelyTyped/blob/master/whatwg-fetch/index.d.ts#L39

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Domain: lib.d.ts The issue relates to the different libraries shipped with TypeScript Help Wanted You can do this
Projects
None yet
Development

No branches or pull requests