microsoft / microsoft/TypeScript

Set esModuleInterop to "true" by default

Abierto
#41,139 11 comentarios 2 reacciones 0 asignados Ver en GitHub

Nadie ha tomado este issue todavía.

In Discussion Suggestion
Lenguaje dominante
Go
Estrellas
111k
Forks
14.3k
Merge medio
2 d 4 h
PR fusionados (30 d)
132

Descripción

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.

Guía de contribución

Abrir la guía de contribución

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Línea de trabajo

Empieza rastreando cómo se representa esModuleInterop en tsconfig.json y cómo lo inicializa tsc --init; después, evalúa las consecuencias para el compilador y el JavaScript generado de cambiar su valor predeterminado. El trabajo estaría terminado cuando se hayan resuelto las implicaciones del breaking change y se haya establecido cómo debe funcionar el comportamiento de exclusión voluntaria para los proyectos existentes.

Escrito por el modelo de indexación a partir del texto del issue.

Evaluación

Stack tecnológico
javascript, typescript
Área
compilers
Tipo de issue
Nueva funcionalidad
Dificultad
5/5
Tiempo estimado
Más de una semana
Estado de actividad
Estancado
Claridad
Bastante claro
Aptitud para principiantes
25/100

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.