Shaun Luttin Shaun Luttin - 1 month ago 8x
TypeScript Question

Cannot find name 'Symbol' in whatwg-fetch type declaration file


file at dt~whatwg-fetch includes the following declaration.

declare class Headers {
// other code ommited
[Symbol.iterator](): IterableIterator<[string, string]>;

We've tried to create a workaround interface without success. None of the following work. What will?

interface Symbol {}

interface Symbol<T> {}

interface Symbol {
iterator: IterableIterator<[string, string]>

interface Symbol<T> {
iterator: IterableIterator<[string, string]>


We've seen Typescript Cannot find name 'IterableIterator' and the recommendation is to target es6. Is that required?


Symbol is new to ES6 and because of that you'll need to target your compiler to that.
To do that specify that the target in the compiler options is "es6".

The definition for Symbol can be found in the lib.es6.d.ts (while it's missing in the default lib.d.ts)


You can just polyfill that part yourself, you just need to copy the needed parts from the lib.es6.d.ts file and put it in your own file and reference it.

I copied what needed for the code you posted and it's in this playground.
It might have more than actually needed, so play around with that.