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

readonly-keyword fixer adds the readonly modifier in the wrong place for decorated class properties #81

Closed
clarkdave opened this issue Apr 23, 2018 · 1 comment · Fixed by #113

Comments

@clarkdave
Copy link

This requires experimentalDecorators: true in tsconfig.


Given the following TypeScript:

class MyEntity {
  @PrimaryGeneratedColumn() id!: number

  @Column('text') name!: number
}

The readonly-keyword fixer outputs:

class MyEntity {
  readonly @PrimaryGeneratedColumn() id!: number

  readonly @Column('text') name!: number
}

This is invalid TypeScript syntax and fails to compile. The correct syntax for decorators and the readonly modifier should be:

class MyEntity {
  @PrimaryGeneratedColumn() readonly id!: number

  @Column('text') readonly name!: number
}

Other notes

  • The tslint rule does detect the readonly modifier if it is already present in the correct place
  • Applying the quick fix again will continue prepending readonly to the line, e.g. readonly readonly readonly readonly @Column('text') name!: number
@clarkdave clarkdave changed the title readonly-keyword fixer doesn't adds the readonly modifier in the wrong place for decorated class properties readonly-keyword fixer adds the readonly modifier in the wrong place for decorated class properties Apr 23, 2018
@jonaskello
Copy link
Owner

This seems like an obvious bug. If someone would like to attempt a PR that would be much appreciated, otherwise I will fix it as soon as time allows.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants