-
Notifications
You must be signed in to change notification settings - Fork 1.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Can't get iterator from iterable object #1163
Comments
+1 This simple code does not work
There seems to be |
Are there some process for this? |
Getting the same error on 0.32 |
Any news on this? |
I think I found a half decent workaround that allows you to extract an iterator from an iterable object. It should work for any arbitrary Exampletype IterFn<T: Object> = $PropertyType<T, '@@iterator'>
function extractIteratorFn<T: Object>(target: T): IterFn<T> {
return target[Symbol.iterator]
}
function isIterableObject(target: mixed): boolean %checks {
return (
target != null &&
typeof target === 'object' &&
typeof extractIteratorFn(target) === 'function'
)
}
function intoIterator<T: Object>(target: T): Iterator<*> {
return extractIteratorFn(target).call(target)
} |
Any status? |
@karel-3d Your fix doesn't seem to work anymore.
|
FYI, this works(0.61) for me: /* @flow */
export class Iter {
/*:: @@iterator(): Iterator<T> { return ({}: any); } */
// $FlowFixMe - computed property
[Symbol.iterator](): Iterator<T> {
return this;
}
next(): IteratorResult<T, void> {
return {
done: true
}
}
} |
Anyone has any ideal why flow is unable to infer following code properly. It reports class IterableObject<a> implements Iterable<a> {
+@@iterator: () => Iterator<a>
+iterator: () => Iterator<a>
}
Object.defineProperty(IterableObject.prototype, Symbol.iterator, {
value() {
return this.iterator()
}
})
class WorkingIterable<a> extends IterableObject<a> {
source: Set<a>
constructor(source: Set<a>) {
super()
this.source = source
}
*iterator(): Iterator<a> {
for (let item of this.source) {
yield item
}
}
}
class BreakingIterable<a> extends IterableObject<a> {
+source: Set<a>
constructor(source: Set<a>) {
super()
this.source = source
}
*iterator() {
for (let item of this.source) {
yield item
}
}
} |
I have published iterable.flow package to npm to overcome this issue until it's properly fixed. |
PING! Flow 0.89, and when I add |
When I try to get
iterator
fromiterable
object using Symbol.iteratorflow check
produces error:I have the same problem with
Iterable
interface:The text was updated successfully, but these errors were encountered: