microsoft / microsoft/TypeScript
Type inference for async generators
まだ誰も着手していません。
- 主要言語
- Go
- スター
- 111k
- フォーク
- 14.3k
- 平均マージ
- 2日 4時間
- マージ済み PR(30日)
- 132
説明
Suggestion
It would be amazing if typescript could infer types from async generators.
The following is valid javascript, thus, I think, it should be valid typescript and type of x should be inferred.
Today it fails with Parameter 'x' implicitly has 'any' type.
async function forever(x) {
for await (const unused of x) {
void unused;
}
}
async function* test() {
for (;;) {
await something();
yield;
}
}
forever(test());
🔍 Search Terms
async generator, async iterator, type inference, infer types
✅ Viability Checklist
My suggestion meets these guidelines:
- This wouldn't be a breaking change in existing TypeScript/JavaScript code
- This wouldn't change the runtime behavior of existing JavaScript code
- This could be implemented without emitting different JS based on the types of the expressions
- This isn't a runtime feature (e.g. library functionality, non-ECMAScript syntax with JavaScript output, new syntax sugar for JS, etc.)
- This feature would agree with the rest of TypeScript's Design Goals.
⭐ Suggestion
Treat type of x as "any async iterator would do" thus including any async generator function.
📃 Motivating Example
My own use... forever/background (async) processes/
💻 Use Cases
Today, I need to type this explicitly, which is unnecessarily verbose.
In the long run, it would allow composing async functions same as type inference helps composing plain functions today.
I get it that type inference for async iterables/iterators/generators opens a huge can of worms, like:
- type narrowing, like #36687 or in this vein
- yield expression return type #36967
- generator yielded type #32523
コントリビューションガイド
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
調査の方向性
報告されている async generator の例から始め、forever(test()) に対する現在の implicit-any 診断を確認してください。ファイル、テスト、エントリポイントは指定されていないため、#36687、#36967、#32523 の関連する懸念を確認してください。async iterators と generators の対象範囲および期待される推論動作が確定すれば完了です。
索引モデルが issue の本文から書いたものです。
評価
- 技術スタック
- javascript, typescript
- 領域
- compilers
- issue の種類
- 機能追加
- 難易度
- 5/5
- 見積もり時間
- 1週間以上
- 活発さ
- 停滞
- 明瞭さ
- おおむね明確
- 初心者へのやさしさ
- 25/100