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

Cannot add typescript definite assignment assertions to class properties #1012

Closed
lokshunhung opened this issue Dec 10, 2021 · 2 comments · Fixed by #1013
Closed

Cannot add typescript definite assignment assertions to class properties #1012

lokshunhung opened this issue Dec 10, 2021 · 2 comments · Fixed by #1013

Comments

@lokshunhung
Copy link
Contributor

lokshunhung commented Dec 10, 2021

Recast version: 0.20.5
Node version: 14.18.2
Mac OS X version: 12.0.1

Repro: https://github.com/lokshunhung/recast-definite-repro

AST explorer


recast with recast/parser/typescript can remove definite assignment assertions for class properties by setting ClassProperty.definite = false (originally true)

// Before
class A {
  foo!: string;
}

// After
class A {
  foo: string;
}

but cannot add definite assignment assertions for class properties by setting ClassProperty.definite = true (originally undefined)

// Before
class A {
  foo: string;
}

// After
class A {
  foo: string;
}

// should be `foo!: string;`
@eventualbuddha
Copy link
Collaborator

It looks like recast doesn't know about that property:

if (n.typeAnnotation) {

Should be pretty easy to fix. Want to submit a PR?

@lokshunhung
Copy link
Contributor Author

@eventualbuddha Sure, #1013

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

Successfully merging a pull request may close this issue.

2 participants