TypeScript icon indicating copy to clipboard operation
TypeScript copied to clipboard

TS does not know about the existence of the window.fetch?

Open acopalipsis opened this issue 10 years ago • 10 comments

window.fetch(...)

error TS2304: Cannot find name 'fetch'.

acopalipsis avatar Jun 04 '16 10:06 acopalipsis

Fetch is only just coming to Edge 14. The tool located at Microsoft/TSJS-lib-generator is what deals with generating the library off of Edge with certain modifications and overrides. That then is what is checked into TypeScript.

kitsonk avatar Jun 04 '16 11:06 kitsonk

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 avatar Jun 04 '16 18:06 mhegazy

if you do not mind, we would like to keep this issue open until it is fixed.

mhegazy avatar Jun 04 '16 19:06 mhegazy

I've used whatwg-fetch typings https://github.com/alm-tools/alm/blob/c7d31e48864a96379fabe27d1bb507ccce3e9319/src/typings.json#L28 with both https://github.com/github/fetch and https://www.npmjs.com/package/node-fetch :rose:

basarat avatar Jun 05 '16 01:06 basarat

@basarat Correct there is a fetch.d.ts that works quite well.

One thing to consider is that fetch relies on a Promise. So using target=ES5 will complain about Promise missing:

error TS2304: Cannot find name 'Promise'.

Are there different versions of lib.d.ts depending on the target param? If so, then fetch should only be added to ES6 target.

styfle avatar Jun 18 '16 14:06 styfle

Any updates on this? Thanks

priyajeet avatar Oct 12 '16 01:10 priyajeet

It is open as accepting PR with a Milestone of the community (noted by the labels and milestone on the right of the issue), which is an indication that the core TypeScript do not currently have the resources to address this as a priority, but anyone in the community is more than welcome to contribute it.

kitsonk avatar Oct 12 '16 06:10 kitsonk

Duplicate of #4948

ghost avatar Oct 21 '16 14:10 ghost

Any updates on this? I am unable to find a working fetch dts file, am i missing something?

mhgamework avatar Mar 28 '17 09:03 mhgamework

@mhgamework In the latest TypeScript, fetch is available with --lib dom.

ghost avatar Mar 28 '17 14:03 ghost