microsoft / microsoft/TypeScript
Set esModuleInterop to "true" by default
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
Search Terms
- esModuleInterop
Suggestion
Change esModuleInterop from being an opt-in to instead be an opt-out, taking one step further towards deprecating the non-esModuleInterop mode and make esModuleInterop the only supported mode going forward (which has to be the long term goal).
Use Cases
When Typescript 2.7 introduced esModuleInterop almost 3 years ago it emphasized clearly that:
We highly recommend applying it both to new and existing projects.
esModuleInterop is also a recommended option to set in tsconfig.json and when one runs tsc --init it gets set to true automatically.
However, the fact that it still is opt-in makes that non-esModuleInterop mode is still very prevalent, which kind of works against the very problems it was meant to fix – as rather than having just the pre-esModuleInterop functionality, modules now have to try to make things work across both options – and on top of that increasingly have to work with TS-validated JS.
All in all, that causes problems: https://github.com/fastify/env-schema/pull/17
And is hard to wrap ones head around: https://github.com/fox1t/modules-playground
Even if one really tries: https://github.com/fox1t/modules-playground/pull/3
Checklist
My suggestion meets these guidelines:
- This wouldn't be a breaking change in existing TypeScript/JavaScript code
- It would for all code which haven't yet adopted
esModuleInterop, but it would make it easier to get TypeScript and JavaScript code to stay compatible with one another
- It would for all code which haven't yet adopted
- 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
- It would emit different JS for all code which haven't yet adopted
esModuleInterop, but it would make it easier to get TypeScript and JavaScript code to stay compatible with one another
- It would emit different JS for all code which haven't yet adopted
- 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.
- Apart from
Do not cause substantial breaking changes from TypeScript 1.0.
- Apart from
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 nachzuverfolgen, wie esModuleInterop in tsconfig.json dargestellt und von tsc --init initialisiert wird, und untersuche anschließend die Auswirkungen auf Compiler und erzeugtes JavaScript, wenn der Standardwert geändert wird. Die Aufgabe wäre abgeschlossen, wenn die Auswirkungen der Breaking Change geklärt sind und feststeht, wie sich das Opt-out-Verhalten für bestehende Projekte verhalten soll.
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
- 25/100