Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
frigus02 opened this issue Nov 23, 2023 · 1 comment Β· Fixed by #56732
Assignees
Labels
Bug A bug in TypeScript Fix Available A PR has been opened for this issue

Comments

@frigus02
Copy link
Contributor

frigus02 commented Nov 23, 2023

πŸ”Ž 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.
  • ...
@frigus02 frigus02 changed the title Broken ts.transpileModule() emit when imported type shadows type but not constructor of global symbol Incorrect ts.transpileModule() emit when imported type shadows type but not constructor of global symbol Nov 23, 2023
@andrewbranch andrewbranch self-assigned this Nov 27, 2023
@andrewbranch andrewbranch added the Bug A bug in TypeScript label Nov 27, 2023
@andrewbranch andrewbranch added this to the TypeScript 5.4.0 milestone Nov 27, 2023
@frigus02
Copy link
Contributor Author

frigus02 commented Dec 8, 2023

I've been using frigus02@cfe3335 to find and fix issues in our code base. If this comes close to an acceptable fix, I'd be happy to clean up and open a PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug A bug in TypeScript Fix Available A PR has been opened for this issue
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants