microsoft / microsoft/TypeScript
esModuleInterop should work even when compiling to esnext modules
Nessuno ha ancora preso questa issue.
- Lingua principale
- Go
- Stelle
- 111k
- Fork
- 14.4k
- Merge medio
- 1g 19h
- PR unite (30g)
- 117
Descrizione
TypeScript Version: 2.7.2
Search Terms: esModuleInterop, esnext, modules, import, export, default
Code
With this type definition:
declare function fn(): void;
declare module "external" {
export = fn;
}
Running with:
tsc --esModuleInterop --module esnext
Produces these errors when importing:
import fn1 from 'external'; // error TS1192: Module '"external"' has no default export.
import fn2 = require('external'); // error TS1202: Import assignment cannot be used when targeting ECMAScript modules.
But, if you use commonjs modules:
tsc --esModuleInterop --module commonjs
It works as expected (because of --esModuleInterop)
import fn1 from 'external'; // works
import fn2 = require('external'); // works
Expected behavior:
It is understandable that the type checker doesn't want to pretend the import is interop'd when it's not compiling in the helpers.
But if you've specified --esModuleInterop and --module esnext the assumption from the type checker should be that an external system is applying the interop. Otherwise why would you specify --esModuleInterop?
Playground Link: https://github.com/jamiebuilds/ts-bug
Guida per i contributori
Apri la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Direzione di ricerca
Riproduci gli import segnalati con tsc usando --esModuleInterop e --module esnext, quindi confronta i diagnostici con il caso commonjs. Traccia la gestione da parte del compilatore degli import predefiniti e delle assegnazioni di importazione per le dichiarazioni export =; il lavoro è completato quando il caso esnext segue il comportamento di interoperabilità richiesto senza regredire rispetto al comportamento commonjs.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Valutazione
- Stack tecnologico
- typescript
- Ambito
- compilers
- Tipo di issue
- Bug
- Difficoltà
- 4/5
- Tempo stimato
- 3-5 giorni
- Stato di attività
- Ferma
- Chiarezza
- Abbastanza chiara
- Idoneità per principianti
- 35/100