microsoft / microsoft/TypeScript

Option to report errors enabled by `useDefineForClassFields`, but still transpile using assignment semantics

Offen
#56,298 4 Kommentare 2 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen

Dieses Issue hat noch niemand übernommen.

Awaiting More Feedback Suggestion
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
⭐ 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
  1. What do you want to use this for?
  2. What shortcomings exist with current approaches?
  3. 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

Beitragsleitfaden öffnen

Erste Schritte

  1. Lies das ganze Issue und danach den Beitragsleitfaden des Projekts.
  2. Schreib ins Issue, dass du es übernimmst — das erspart doppelte Arbeit.
  3. Forke das Repository und arbeite in einem Branch.
  4. Ö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

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.