microsoft / microsoft/TypeScript
Suggestion: add flag to notify when awaiting a non-promise
Dieses Issue hat noch niemand übernommen.
- Vorherrschende Sprache
- Go
- Sterne
- 111k
- Forks
- 14.3k
- Ø Merge
- 1 T. 19 Std.
- Gemergte PRs (30 T.)
- 117
Beschreibung
Search Terms
async promise force error
Suggestion
Add a tsconfig.json flag to display info/warning/error when awaiting non-PromiseLike code. This will catch developer errors.
Use Cases
Catch developer errors when writing async code.
Example
The following code is valid:
await Promise.all(urls.map(url => {
fetch(url);
});
console.log('fetching complete');
The developer intends to do something once all the fetches complete, but since map is not returning any value, it ends up awaiting [undefined, undefined, ...], which means fetching complete is logged before the fetches complete. It would be nice if TS gave an info/warning/error in this case.
The correct code is:
await Promise.all(urls.map(url => {
return fetch(url);
});
console.log('fetching complete');
This example is paired down to the bare minimum for simplicity, but IRL code is more complex.
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, etc.)
- This feature would agree with the rest of TypeScript's Design Goals.
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
Da im Issue keine Quelldatei oder kein Test angegeben ist, beginne damit, die Verarbeitung von await-Ausdrücken durch TypeScript und die tsconfig-Diagnosen zu lokalisieren. Die Aufgabe ist erledigt, wenn eine konfigurierbare Info, Warnung oder ein Fehler für das Awaiten von Code, der nicht PromiseLike ist, definiert und implementiert wurde und eine Abdeckung für das bereitgestellte Promise.all-Beispiel vorhanden ist.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Bewertung
- Tech-Stack
- typescript
- Bereich
- compilers
- Issue-Typ
- Feature
- Schwierigkeit
- 5/5
- Geschätzter Aufwand
- Über eine Woche
- Aktivitätsstatus
- Veraltet
- Klarheit
- Größtenteils klar
- Anfängerfreundlichkeit
- 35/100