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

SyntaxError: Stage 2 decorators cannot be used to decorate parameters #101

Closed
bbenoist opened this issue Oct 15, 2019 · 1 comment
Closed

Comments

@bbenoist
Copy link

bbenoist commented Oct 15, 2019

Hi, thanks for your work!

I have an error with one of my TypeScript project.
I've made a simple project reproducing the issue: bbenoist/prettier-plugin-import-sort-arg-decorator-bug (branch import-sort-cli)

The following valid TypeScript code:

function ArgDecorator(_target: Record<string, any>, _propertyKey: string | symbol, _parameterIndex: number): void {
    console.log(_target, _propertyKey, _parameterIndex)
}

class MyClass {
    myFunction(@ArgDecorator myArg: string){
        console.log(myArg);
    }
}

const foo = new MyClass;
foo.myFunction("hello");

Gives this error (full log - branch import-sort-cli):

$ npm run-script import-sort-cli
> import-sort-cli
...
src/index.ts:
SyntaxError: Stage 2 decorators cannot be used to decorate parameters (10:13)
...
@bbenoist
Copy link
Author

Fixed with adding "parser": "typescript" in my package.json config:

  "importSort": {
    ".js, .jsx, .ts, .tsx": {
      "style": "module",
      "parser": "typescript"
    }
  }

yuhuiX added a commit to yuhuiX/my-angular-project that referenced this issue Sep 22, 2020
Fix found in renke/import-sort#101.
Note that a global typescript module has to be available for this
extension.
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

1 participant