microsoft / microsoft/TypeScript
Should disallow using the result of calling a void-returning function
Dieses Issue hat noch niemand übernommen.
- Vorherrschende Sprache
- Go
- Sterne
- 111k
- Forks
- 14.3k
- Ø Merge
- 2 T. 4 Std.
- Gemergte PRs (30 T.)
- 132
Beschreibung
TypeScript Version: 4.1.0-dev.20201008
Search Terms: disallow function call void return usage warn error
Code
function doesntReturn() {
// no return statement
}
const foo: string = doesntReturn() + 'foo'; // should be an error
Expected behavior:
The expression doesntReturn() + 'foo' should be an error because it uses the value of a void-returning function call. As far as I can tell, there is literally no good reason to use the return value of a function with no return statements like this.
This is similar to the current behavior of disallowing void-returning expressions inside control flow (issue #26262). It is also similar to the reasoning behind the warning that occurs when using a function value (instead of calling it) in an if condition.
Actual behavior:
No error message is given.
Playground Link: here
Related Issues: #26262
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 verlinkten Playground-Beispiel, um die fehlende Diagnose zu reproduzieren, und lies anschließend den verwandten Issue #26262 zum vergleichbaren Control-Flow-Verhalten. Als abgeschlossen gilt die Aufgabe, wenn der Ausdruck, der das Ergebnis eines Funktionsaufrufs mit void-Rückgabewert verwendet, einen Fehler meldet, während sich das bestehende Beispiel weiterhin wie erwartet verhält.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Bewertung
- Tech-Stack
- typescript
- Bereich
- compilers
- Issue-Typ
- Feature
- Schwierigkeit
- 4/5
- Geschätzter Aufwand
- 3-5 Tage
- Aktivitätsstatus
- Veraltet
- Klarheit
- Größtenteils klar
- Anfängerfreundlichkeit
- 38/100