You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
TS2488 Type must have a '[Symbol.iterator]()' method that returns an iterator. TypeScript Virtual Projects #12707
ERROR :
TS2488 Type must have a 'Symbol.iterator' method that returns an iterator. TypeScript Virtual Project TypeScript Version: 2.1
I am using typescript in a Visual Studio 2015
for (var item of this.listOfTemplate) { //error here
}
changed the title [-]Severity Code Description Project File Line Suppression State Error TS2488 Type must have a '[Symbol.iterator]()' method that returns an iterator. TypeScript Virtual Projects D:\Email Test Application\EmailBuilder\TypeScriptHTMLApp5\app.ts 85 Active[/-][+]TS2488 Type must have a '[Symbol.iterator]()' method that returns an iterator. TypeScript Virtual Projects[/+]on Dec 7, 2016
Make sure the type isn't nullable (have a question mark at the end of the variable name)... that caused this error for me.
Reacted by Jacob Rask, pavproav, Alexander Lyon, WebTalent888, Stephen Langdon, Jonas Zapanta, Marco Rinaldi, Chauncey Garrett, lanye, Aaron Deane and 5 more
add ! to the end of the var that is being spread. E.g. [{}, ...payload!]
Reacted by Chinedu Ekene Okpala, Silke Van den Broeck, Oleg Varlamov, Yk, Raphael Strotz, Ryan Craig Martin, Richard Mayes, Haitam BOUKAA, Brian West, ybwdaisy and 21 more
Reacted by Chinedu Ekene Okpala, Leilenah Mamea, Raphael Strotz, IAMtheIAM, Nathan Cai, Pablo Blanco, lanye, Rabie Nasser, Gerardo Torres, Ed and 1 more
Reacted by Chinedu Ekene Okpala, Raphael Strotz, Dan Tonon, Brian West, Nathan Cai, HeidiAshraf, Alla Gorik, lanye, Gerardo Torres, Ed and 3 more
Activity
[-]Severity Code Description Project File Line Suppression State Error TS2488 Type must have a '[Symbol.iterator]()' method that returns an iterator. TypeScript Virtual Projects D:\Email Test Application\EmailBuilder\TypeScriptHTMLApp5\app.ts 85 Active[/-][+]TS2488 Type must have a '[Symbol.iterator]()' method that returns an iterator. TypeScript Virtual Projects[/+]mhegazy commentedon Dec 7, 2016
you are specifying
target: es6but do not included the neededes6built in definitions in thelib: es6.so either change the target to be
es5. or addes6to yourlibflag.ricklove commentedon Jun 22, 2017
I ran into this also and it took forever to find: Hoping this comment will help others find this note.
I was trying to use for ... of with an array while targeting es6 (es2015).
I solved by doing what Mohamed Hegazy (@mhegazy) said, but I just added "es2015.iterable" instead of all of es6.
keywords: typescript array symbol iterator error
mikejune commentedon Sep 19, 2017
I'm trying to use the spread operator in this manner:
error is on the
...payloadpart of the code. issue still remains with"es2015.iterable"intsconfig.jsonIAmCoder commentedon Apr 27, 2018
Make sure the type isn't nullable (have a question mark at the end of the variable name)... that caused this error for me.
JakobJingleheimer commentedon Jun 20, 2018
This also happens with an interface that fakes a tuple:
chicken-suop commentedon Jan 8, 2020
add
!to the end of the var that is being spread. E.g.[{}, ...payload!]slavafomin commentedon Feb 6, 2020
Hello!
I'm seeing this issue as well.
I have the following interface:
And I'm trying to spread it this way:
All I want is to define a more specific type of the first element of the array.
slavafomin commentedon Feb 6, 2020
I've found a working solution for cases mentioned by me, jshado1 and Mike June (@mikejune).
The type should be defined this way:
Or more compact:
The trick is to add your more specific properties on top of array of string type (
Array<string>).I've tested it and it works great, type checking is working correctly everywhere I expect it to work.
Here's the TS Playground to test this out.
AllStackDev1 commentedon May 18, 2020
type PartialRecord<K extends keyof any, T> = Partial<Record<K, T>>;...endpoint.middlewares[method]-- !works...endpoint.middlewares[method]!--worksCan you please explain what this does, because it helped in my case.
chicken-suop commentedon Jun 25, 2020
@MrCEO63 Did you check https://stackoverflow.com/questions/42273853/in-typescript-what-is-the-exclamation-mark-bang-operator-when-dereferenci?
rileydev23 commentedon Sep 20, 2022
LSDJHFKSJDFKSJD was so easy, i love u