Skip to content

Cannot add typescript definite assignment assertions to class properties #1012

@lokshunhung

Description

@lokshunhung

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;`

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions