Symbol.iterator for enum values in Typescript -
i use symbol.iterator enum iterate on values this:
enum color {red, green, blue} color[symbol.iterator] = function*():iterator<color> { yield color.red; yield color.green; yield color.blue; } (let color of color){ alert(color); } but not work. work? important me not having change for/of line.
the error got on for/of line: ts2488: type must have 'symbol.iterator' method returns iterator.
the closest can is:
enum color {red, green, blue} module color { export function* values() { yield color.red; yield color.green; yield color.blue; } } (let color of color.values()) { alert(color); } although modifies for/of loop. of you.
Comments
Post a Comment