Skip to content

[Typescript] Prettier removes question mark from optional computed class property #6569

@spencersutton

Description

@spencersutton

Prettier 1.18.2
Playground link

--parser typescript

Input:

const bar = 'bar';
class Foo {
    [bar]?;
    [1]?;
    ['baz']?;
}

Output:

const bar = "bar";
class Foo {
  [bar];
  [1]?;
  ["baz"]?;
}

Expected behavior:
Prettier should preserve ? in output. Expected output:

const bar = "bar";

class Foo {
  [bar]?;
  [1]?;
  ["baz"]?;
}

This only happens when the computed property is a variable.

Metadata

Metadata

Assignees

No one assigned

    Labels

    lang:typescriptIssues affecting TypeScript-specific constructs (not general JS issues)locked-due-to-inactivityPlease open a new issue and fill out the template instead of commenting.scope:dependencyIssues that cannot be solved inside Prettier itself, and must be fixed in a dependency

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions