microsoft / microsoft/TypeScript

Class with 'private [Symbol.iterator]' is iterable outside of the class body

オープン
#42,190 コメント 0 件 リアクション 3 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

Bug Domain: classes
主要言語
Go
スター
111k
フォーク
14.3k
平均マージ
2日 4時間
マージ済み PR(30日)
132

説明

TypeScript Version: 4.2.0-dev.20210103, seems to be a regression in 3.6, probably introduced by strictly typed generators (cc @rbuckton)

Search Terms: iteration, private

Expected behavior:

Errors like in v3.5:

Type 'C' is not assignable to type 'Iterable<string>'.
  Property '[Symbol.iterator]' is private in type 'C' but not in type 'Iterable<string>'.

Type 'D' is not assignable to type 'Iterable<string>'.
  Types of property '[Symbol.iterator]' are incompatible.
    Type '() => D' is not assignable to type '() => Iterator<string>'.
      Type 'D' is not assignable to type 'Iterator<string>'.
        Property 'next' is private in type 'D' but not in type 'Iterator<string>'.

Actual behavior:

No error on iteration inside and outside of the class body.

Related Issues: #42051 and #42104

Code

class C {
    private [Symbol.iterator]() {
        return this;
    }

    public next() {
        return {value: 'a', done: false};
    }
}

class D {
    public [Symbol.iterator]() {
        return this;
    }

    private next() {
        return {value: 'a', done: false};
    }
}


function fn() {
    for (const _ of new C()) {
    }

    for (const _ of new D()) {}
}
Compiler Options
{
  "compilerOptions": {
    "noImplicitAny": true,
    "strictNullChecks": true,
    "strictFunctionTypes": true,
    "strictPropertyInitialization": true,
    "strictBindCallApply": true,
    "noImplicitThis": true,
    "noImplicitReturns": true,
    "alwaysStrict": true,
    "esModuleInterop": true,
    "declaration": true,
    "experimentalDecorators": true,
    "emitDecoratorMetadata": true,
    "moduleResolution": 2,
    "target": "ES2017",
    "jsx": "React",
    "module": "ESNext"
  }
}

Playground Link: Provided

コントリビューションガイド

コントリビューションガイドを開く

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

調査の方向性

提供されたPlaygroundの再現例から始め、TypeScript 4.2-devでの動作を、報告されている3.5での動作と比較します。関連するissue #42051および#42104をコンテキストとして使用してください。コンパイラがprivate [Symbol.iterator]およびprivate nextメンバーをどのように処理するかを追跡します。無効な反復で期待される代入可能性エラーが発生すれば完了です。

索引モデルが issue の本文から書いたものです。

評価

技術スタック
typescript
領域
compilers
issue の種類
バグ
難易度
4/5
見積もり時間
3〜5日
活発さ
停滞
明瞭さ
明確に書かれている
初心者へのやさしさ
35/100

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。