-
Notifications
You must be signed in to change notification settings - Fork 13.2k
Open
Labels
Domain: ES ModulesThe issue relates to import/export style module behaviorThe issue relates to import/export style module behaviorIn DiscussionNot yet reached consensusNot yet reached consensusSuggestionAn idea for TypeScriptAn idea for TypeScript
Description
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'); // worksExpected 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
torifat, sindresorhus, 5id, itsMapleLeaf, rosskevin and 6 more
Metadata
Metadata
Assignees
Labels
Domain: ES ModulesThe issue relates to import/export style module behaviorThe issue relates to import/export style module behaviorIn DiscussionNot yet reached consensusNot yet reached consensusSuggestionAn idea for TypeScriptAn idea for TypeScript