Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

The d.ts 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]> 
}

Edit

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

http://www.typescriptlang.org/docs/handbook/iterators-and-generators.html

like image 269
Shaun Luttin Avatar asked Sep 01 '16 20:09

Shaun Luttin


1 Answers

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)


Edit

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.

like image 168
Nitzan Tomer Avatar answered Sep 30 '22 20:09

Nitzan Tomer