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

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

Closed
RomainLanz opened this issue Jun 27, 2024 · 5 comments Β· Fixed by #59325
Closed

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

RomainLanz opened this issue Jun 27, 2024 · 5 comments Β· Fixed by #59325
Assignees
Labels
Bug A bug in TypeScript Domain: Declaration Emit The issue relates to the emission of d.ts files Fix Available A PR has been opened for this issue Recent Regression This is a new regression just found in the last major/minor version of TypeScript.

Comments

@RomainLanz
Copy link

RomainLanz commented Jun 27, 2024

πŸ”Ž Search Terms

remove import compilation decorator

πŸ•— Version & Regression Information

  • This changed between versions 5.4 and 5.5

⏯ 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
Copy link
Author

Here is a discussion that may be related : #54493 (comment)

@DanielRosenwasser DanielRosenwasser added Bug A bug in TypeScript Domain: Declaration Emit The issue relates to the emission of d.ts files Recent Regression This is a new regression just found in the last major/minor version of TypeScript. labels Jun 28, 2024
@DanielRosenwasser DanielRosenwasser added this to the TypeScript 5.6.0 milestone Jun 28, 2024
@Max10240
Copy link

Max10240 commented Jun 28, 2024

met this too

@zanminkian
Copy link

That means a project which enables following features at the same time will be unusable under TS 5.5:

  1. enable both emitDecoratorMetadata and experimentalDecorators in tsconfig.
  2. use declare keyword for class properties.
  3. verbatimModuleSyntax is false.

Some of my projects cannot upgrade to TS 5.5 too.

@jakebailey
Copy link
Member

jakebailey commented Jul 17, 2024

Using https://www.npmjs.com/package/every-ts, this bisects to #58366. @weswigham

@jakebailey
Copy link
Member

It looks like this bit was added:

        if (location.flags & NodeFlags.Ambient) {
            return; // References within types and declaration files are never going to contribute to retaining a JS import
        }

Which explicitly skips marking references for declare.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug A bug in TypeScript Domain: Declaration Emit The issue relates to the emission of d.ts files Fix Available A PR has been opened for this issue Recent Regression This is a new regression just found in the last major/minor version of TypeScript.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

7 participants