Skip to content

Incorrect ts.transpileModule() emit when imported type shadows type but not constructor of global symbol #56521

Description

@frigus02

🔎 Search Terms

transpileModule, isolatedModules

🕗 Version & Regression Information

  • This is the behavior in every version I tried: v5.2.2, v5.3.2, v5.4.0-dev.20231123

⏯ Playground Link

Bug Workbench

💻 Code

// @isolatedModulesimport{Date}from"./types";functionfoo(a: Date){constb=newDate(a.year,a.month,a.day);returnb.getTime();}// @filename: types.d.tsexportinterfaceDate{day: number;month: number;year: number;}

🙁 Actual behavior

Regular emit:

functionfoo(a){constb=newDate(a.year,a.month,a.day);returnb.getTime();}

ts.transpileModule() emit:

import{Date}from"./types";functionfoo(a){constb=newDate(a.year,a.month,a.day);returnb.getTime();}

The ts.transpileModule() emit has a runtime error because the imported Date either doesn't exist or doesn't have a constructor.

🙂 Expected behavior

Same (or at least runtime equivalent) emit of transpileModule.

Additional information about the issue

I realize this code is probably not ideal. I was honestly surprised that this type-checks. I'm happy with any solution here:

  • Make this code an error in all configurations.
  • Make isolatedModules require import type.
  • ...

Metadata

Metadata

Labels

BugA bug in TypeScriptFix AvailableA PR has been opened for this issue

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions