facebook / facebook/flow

Can't get iterator from iterable object

未關閉
#1,163 12 則留言 15 個 reaction 已指派 0 人 在 GitHub 檢視
ES2015+
主要語言
Rust
星號
22.3k
分支
1.9k
PR 合併指標
30 天內沒有已合併 PR

描述

When I try to get `iterator` from `iterable` object using [Symbol.iterator](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Symbol/iterator)

``` ts
/* @flow */

'use strict';

const a = [1, 2, 3];
for (const value of a[Symbol.iterator]()) {
console.log(value);
}
```

`flow check` produces error:

```
test.js:6
6: for (const value of a[Symbol.iterator]()) {
^^^^^^^^^^^^^^^^^^ access of computed property/element. Element cannot be accessed with
6: for (const value of a[Symbol.iterator]()) {
^^^^^^^^^^^^^^^ string

```

I have the same problem with `Iterable` interface:

``` ts
/* @flow */

'use strict';

const iterable: Iterable = [1, 2, 3];
const iter = iterable[Symbol.iterator];
```

```
$ flow check
test.js:6
6: const iter = iterable[Symbol.iterator];
^^^^^^^^^^^^^^^^^^^^^^^^^ access of computed property/element. Indexable signature not found in
6: const iter = iterable[Symbol.iterator];
^^^^^^^^ $Iterable
```

```
$ flow version
Flow, a static type checker for JavaScript, version 0.19.1
```

貢獻指南

開啟貢獻指南

評估

這個 Issue 還沒有評估資料。

把新 issue 寄到你的電子郵件信箱

精選適合新手參與的 GitHub issue 摘要。