enums - How to iterate a string literal type in typescript -
how can iterate string literal type in typescript?
for example define type
type name = "bill gates" | "steve jobs" | "linus torvalds";
i want iterate this
for (let name of name) { console.log("possible name: " + name); }
or not possible in typescript?
since typescript compiler, none of typing information present in runtime. means unfortunately cannot iterate through type.
depending on you're trying possible use enums store indices of names can retrieve in array.
Comments
Post a Comment