microsoft / microsoft/TypeScript
Never returning functions should disable getter return requirement
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
declare const error: () => never;
const o = { get p() { error(); } };
Produces the error A 'get' accessor must return a value.(2378). Throwing an error directly would not. I feel similar to https://www.typescriptlang.org/docs/handbook/release-notes/typescript-3-7.html#better-support-for-never-returning-functions, a never-returning-function should have the same effect.
Afaik "control flow analysis happens before typechecking", so this would only work, when the function has a declared type. That's in line with the linked existing improvement in TS 3.7, and to be expected.
🔍 Search Terms
Getter Get accessor must return a value never returning function error throw
✅ 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.
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 damit, die Prüfung von Rückgabewerten von Gettern und die Behandlung des Kontrollflusses für deklarierte Funktionen, die niemals zurückkehren, nachzuverfolgen, wobei du den TypeScript 3.7-Release-Hinweis als Kontext verwendest. Füge eine Regressionstestabdeckung für einen Getter hinzu, der eine Funktion aufruft, die mit dem Rückgabetyp never deklariert ist, und überprüfe, dass die Getter-Diagnose unterdrückt wird, während gewöhnliche Pfade ohne Rückgabe weiterhin einen Wert erfordern.
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
- 35/100