microsoft / microsoft/TypeScript
Type inference for async generators
Dieses Issue hat noch niemand übernommen.
- Vorherrschende Sprache
- Go
- Sterne
- 111k
- Forks
- 14.4k
- Ø Merge
- 1 T. 19 Std.
- Gemergte PRs (30 T.)
- 117
Beschreibung
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
Beitragsleitfaden
Erste Schritte
- Lies das ganze Issue und danach den Beitragsleitfaden des Projekts.
- Schreib ins Issue, dass du es übernimmst — das erspart doppelte Arbeit.
- Forke das Repository und arbeite in einem Branch.
- Öffne einen Pull Request, der die Issue-Nummer nennt.
Rechercherichtung
Beginne mit dem gemeldeten Beispiel für einen async generator und überprüfe die aktuelle implicit-any-Diagnose für forever(test()). Es werden keine Dateien, Tests oder Einstiegspunkte genannt; prüfe die damit verbundenen Anliegen in #36687, #36967 und #32523. Erledigt ist die Aufgabe, wenn der Umfang und das erwartete Inferenzverhalten für async iterators und generators festgelegt sind.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Bewertung
- Tech-Stack
- javascript, typescript
- Bereich
- compilers
- Issue-Typ
- Feature
- Schwierigkeit
- 5/5
- Geschätzter Aufwand
- Über eine Woche
- Aktivitätsstatus
- Veraltet
- Klarheit
- Größtenteils klar
- Anfängerfreundlichkeit
- 25/100