Skip to content

TS issue: Stop adding unnecessary parentheses for decorators #11839

@dreamerblue

Description

@dreamerblue

Prettier 2.4.1
Playground link

--parser typescript

Input:

@test().x('global').y()
class X {}

Output:

@(test().x("global").y())
class X {}

Expected behavior:

@test().x('global').y()
class X {}

In TypeScript, the two decorator usages (Input and Output above) are same. They will be compiled to JS like:

let X = class X {
};
X = __decorate([
    // from the input
    test().x('global').y()
    // and from the output. they are same
    (test().x('global').y())
], X);

But the Input's style (no parentheses) is easier to read and looks better. I found a related PR #5785 caused the issue.

Maybe Prettier should support parser based format behavior or parser based config? Only babel should add parentheses for decorators but typescript not.

Metadata

Metadata

Assignees

No one assigned

    Labels

    lang:typescriptIssues affecting TypeScript-specific constructs (not general JS issues)

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions