microsoft / microsoft/TypeScript

Set esModuleInterop to "true" by default

Aperta
#41,139 11 commenti 2 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

In Discussion Suggestion
Lingua principale
Go
Stelle
111k
Fork
14.3k
Merge medio
2g 4h
PR unite (30g)
132

Descrizione

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
  • 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
  • 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.

Guida per i contributori

Apri la guida per i contributori

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Direzione di ricerca

Inizia tracciando come esModuleInterop è rappresentato in tsconfig.json e inizializzato da tsc --init, quindi valuta le conseguenze sul compilatore e sul JavaScript emesso della modifica del suo valore predefinito. Il lavoro sarebbe completato quando saranno risolte le implicazioni della breaking change e sarà stabilito come debba funzionare il comportamento di opt-out per i progetti esistenti.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Valutazione

Stack tecnologico
javascript, typescript
Ambito
compilers
Tipo di issue
Funzionalità
Difficoltà
5/5
Tempo stimato
Più di una settimana
Stato di attività
Ferma
Chiarezza
Abbastanza chiara
Idoneità per principianti
25/100

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.