microsoft / TypeScript

TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
https://www.typescriptlang.org
Apache License 2.0
99.01k stars 12.29k forks source link

TS 5.5 - Imports used by decorator output are removed #59051

Open RomainLanz opened 6 days ago

RomainLanz commented 6 days ago

πŸ”Ž Search Terms

remove import compilation decorator

πŸ•— Version & Regression Information

⏯ Playground Link

https://github.com/RomainLanz/typescript-output-issue

npm install
npm run build

πŸ’» Code

import { DateTime } from "luxon";
import { column } from "@adonisjs/lucid/orm";

class User {
  @column.dateTime()
  declare createdAt: DateTime;
}

πŸ™ Actual behavior

When compiled the DateTime import is being removed (because it is only used as a type in our file), but the compilation of @column.dateTime() will use the import.

// ...

import { column } from "@adonisjs/lucid/orm";
class User {
}
__decorate([
    column.dateTime(),
    __metadata("design:type", typeof (_a = typeof DateTime !== "undefined" && DateTime) === "function" ? _a : Object)
], User.prototype, "createdAt", void 0);

πŸ™‚ Expected behavior

The import should be kept like in TypeScript 5.4.

import { DateTime } from "luxon";
import { column } from "@adonisjs/lucid/orm";
class User {
}
__decorate([
    column.dateTime(),
    __metadata("design:type", typeof (_a = typeof DateTime !== "undefined" && DateTime) === "function" ? _a : Object)
], User.prototype, "createdAt", void 0);

Additional information about the issue

No response

RomainLanz commented 6 days ago

Here is a discussion that may be related : https://github.com/microsoft/TypeScript/issues/54493#issuecomment-1615409830

Max10240 commented 5 days ago

met this too