microsoft / microsoft/TypeScript
Generator functions which have a return type of a union of Iterator/AsyncIterator have a yield type of never
まだ誰も着手していません。
- 主要言語
- Go
- スター
- 111k
- フォーク
- 14.3k
- 平均マージ
- 2日 4時間
- マージ済み PR(30日)
- 132
説明
TypeScript Version: 3.7.2
Search terms: generator iterator asynciterator type union never
Code
example.ts
type NumberIterator = Iterator<number> | AsyncIterator<number>;
type NumberGenerator = Generator<number> | AsyncGenerator<number>;
function *numbers(): NumberIterator {
yield 1;
}
A type alias which is a union of Iterator and AsyncIterator is used as the return type of a synchronous generator.
Expected behavior:
Code compiles.
Actual behavior:
example.ts(5,11): error TS2322: Type '1' is not assignable to type 'never'.
If you replace NumberIterator with NumberGenerator as the return type the function above, the code correctly type-checks. Something is wrong here.
Playground Link:
The playground link won’t work because the playground doesn’t support async iterators yet (https://github.com/microsoft/TypeScript-Website/issues/15).
Related Issues:
#30790 Strongly-typed iterator PR
コントリビューションガイド
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
調査の方向性
example.ts の TypeScript 3.7.2 の診断を再現し、NumberIterator と NumberGenerator の戻り値の型を比較します。イテレーターのコンテキストについて関連する issue #30790 を読み、その後、Iterator と AsyncIterator のユニオンを持つ同期ジェネレーターが yield-type-never エラーなしでコンパイルできることを確認します。
索引モデルが issue の本文から書いたものです。
評価
- 技術スタック
- typescript
- 領域
- compilers
- issue の種類
- バグ
- 難易度
- 4/5
- 見積もり時間
- 3〜5日
- 活発さ
- 停滞
- 明瞭さ
- 明確に書かれている
- 初心者へのやさしさ
- 45/100