Reputation: 73
example:
function foo(iterable) {
for (let i of iterable) {}
}
What type could iterable be here asides from any? other examples include Array.from and most of the other iterable data structure constructors.
Upvotes: 3
Views: 1472
Reputation: 73
Iterable is an ES6 feature, so setting your tsc target to "es6" lets you take in an Iterable as a parameter, e.g.
function foo<T>(iterable: Iterable<T>) {
for (let i of iterable) {}
}
Upvotes: 3
Reputation: 4052
You should tell typescript the type of your parameter, so it could compile:
function foo(iterable:Array<any>) {
for (let i of iterable) {}
}
Upvotes: 1