Closed
Description
π 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
π» 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
requireimport type
. - ...