Skip to content

Missing error for isolatedModules: true and export import #45579

Description

@evanw

Bug Report

🔎 Search Terms

isolatedModules true export import type-only namespace

🕗 Version & Regression Information

Version: typescript@4.3.5. This is the behavior in every version I tried.

⏯ Playground Link

N/A since this is a multi-file issue.

💻 Code

  • jsx.ts

    exportnamespaceJSXInternal{exporttypeHTMLAttributes=stringexporttypeComponentChildren=string}
  • factory.ts

    import{JSXInternal}from"./jsx"exportimportJSX=JSXInternal;exportfunctioncreateElement<ElementTypeextendsHTMLElement>(tagName: string,attributes: JSX.HTMLAttributes,
    ...children: JSX.ComponentChildren[]): any{//...}
  • tsconfig.json

    {"compilerOptions": {"target": "ES2015","isolatedModules": true}}

🙁 Actual behavior

Repro:

  1. Run tsc

  2. Inspect factory.js, which looks like this:

    exportfunctioncreateElement(tagName,attributes, ...children){//...}
  3. Add export let foo to the JSXInternal namespace in jsx.ts

  4. Run tsc again

  5. Inspect factory.js, which now looks like this:

    import{JSXInternal}from"./jsx";exportvarJSX=JSXInternal;exportfunctioncreateElement(tagName,attributes, ...children){//...}

🙂 Expected behavior

Since isolatedModules: true is enabled, I did not expect changing an input file to change the output of an unrelated output file. So I guess I expected for this input code to be considered a compile error under isolatedModules: true. I looked around a bit and couldn't find an already-filed issue about this so I filed this issue.

For context, I'm maintaining my own TypeScript parser for esbuild and I'm relying on isolatedModules: true to avoid cross-file compilation dependencies. My understanding is that's what isolatedModules: true is supposed to do (according to TypeScript's own documentation). Indeed TypeScript's ts.transpileModule API also miscompiles this code. This specific problem was brought to my attention by one of my users: evanw/esbuild#1550. Given the definition of isolatedModules, I consider this to be a bug in TypeScript's type checker which should be considering this code an error.

Metadata

Metadata

Labels

BugA bug in TypeScriptFix AvailableA PR has been opened for this issueRescheduledThis issue was previously scheduled to an earlier milestone

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions