microsoft / microsoft/TypeScript
Option to report errors enabled by `useDefineForClassFields`, but still transpile using assignment semantics
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
🔍 Search Terms
"useDefineForClassFields", "class fields errors"
✅ Viability Checklist
- 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 isn't a request to add a new utility type: https://github.com/microsoft/TypeScript/wiki/No-New-Utility-Types
- This feature would agree with the rest of our Design Goals: https://github.com/Microsoft/TypeScript/wiki/TypeScript-Design-Goals
⭐ Suggestion
Add an option to have TSC generate the same errors it currently generates for useDefineForClassFields = True, but while still continuing to transpile fields using the non-spec-compliant assignment semantics.
📃 Motivating Example
We must run TS with useDefineForClassFields = false, because we find the output code size of define semantics unacceptably large.
We want to be certain that our code continues to behave the same way when we are able to ship this code to environments that understand class fields without transpilation.
We want to eliminate from our code base all cases where field definitions behave differently between the 2 semantics, and then prevent them from ever returning.
To do this, it would be extremely helpful if TSC could report errors for code that would behave differently with define semantics, but also continue transpiling with assign semantics.
💻 Use Cases
- What do you want to use this for?
- What shortcomings exist with current approaches?
- What workarounds are you using in the meantime?
For 1:
see the Motivating Example.
For 2 & 3:
The only workaround I know of is to run TSC twice with different options, once for the output we want and once for the errors we want. This is prohibitively expensive to do at scale.
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 der Überprüfung der vorhandenen Compileroption useDefineForClassFields und der beiden im Issue beschriebenen Emit-Modi für Klassenfelder. Vergleiche die mit Define-Semantik erzeugten Diagnosen mit der Ausgabe mit Assignment-Semantik und ermittle anschließend, wie eine separate Prüfoption diese Diagnosen beibehalten könnte, ohne das ausgegebene JavaScript zu ändern; es wird keine Datei und kein Test genannt, daher müsste für den Abschluss eine Abdeckung für beide Modi hinzugefügt werden.
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
- 35/100