Skip to content

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

Closed
@frigus02

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

// @isolatedModules

import {Date} from "./types";

function foo(a: Date) {
  const b = new Date(a.year, a.month, a.day);
  return b.getTime();
}

// @filename: types.d.ts
export interface Date {
  day: number;
  month: number;
  year: number;
}

πŸ™ Actual behavior

Regular emit:

function foo(a) {
  const b = new Date(a.year, a.month, a.day);
  return b.getTime();
}

ts.transpileModule() emit:

import {Date} from "./types";
function foo(a) {
  const b = new Date(a.year, a.month, a.day);
  return b.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

Assignees

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