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

Decorator wrapped around declare or abstract fields are failing since 0.19.8 #3684

Closed
rodrigofuentes opened this issue Mar 7, 2024 · 2 comments

Comments

@rodrigofuentes
Copy link

rodrigofuentes commented Mar 7, 2024

The issue I'm facing is decorated declare or abstract fields are causing an Error: Decorators are not valid here. After some inspection it seems that esbuild supported this until version 0.19.8

Is this no longer supported?

Code example:

function log(target: any, key: string): void {
  console.log(`Logging ${key} function`)
}

abstract class ExampleClass {
  @log
  abstract prop1: string

  @log
  prop2: boolean = true
}

class ExampleClass2 extends ExampleClass {
  prop1: string = "world"
}

Esbuild result:

[ERROR] Decorators are not valid here

    entry.ts:6:2:
      6 │   @log
        ╵   ^

Some playground links:

Working esbuild-playground on version 0.19.7

typescript-playground

@evanw
Copy link
Owner

evanw commented Mar 7, 2024

There are two problems here:

  1. Using decorators like this is legacy TypeScript-specific behavior that requires you to set "experimentalDecorators": true in your tsconfig.json file. You can do this on esbuild's command line with --tsconfig-raw='{"compilerOptions":{"experimentalDecorators":true}}' like this.

  2. This currently only works for declare fields, not for abstract fields. This is an esbuild bug that I can fix (I didn't think about the abstract case).

@rodrigofuentes
Copy link
Author

@evanw abstract support would be awesome thanks.

@evanw evanw closed this as completed in ae5cc17 Mar 14, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants