Skip to content

Decorated property breaks on type annotation instead of decorator (TypeScript, Babylon) #1996

@mafredri

Description

@mafredri

Note: Here I've used 65 as print width to demonstrate the issue.

Input:

class MyContainerComponent {
  @ContentChildren(MyComponent) components: QueryList<MyComponent>;
}

Output:

class MyContainerComponent {
  @ContentChildren(MyComponent) components: QueryList<
    MyComponent
  >;
}

Expected:

class MyContainerComponent {
  @ContentChildren(MyComponent)
  components: QueryList<MyComponent>;
}

My reasoning here is that I think keeping the type annotation whole should take precedence over the decorator statement. Further, this is the behavior we would see if we added another decorator:

class MyContainerComponent {
  @Other()
  @ContentChildren(MyComponent)
  components: QueryList<MyComponent>;
}

I also noticed there's yet another behavior if we decrease print width to 50:

class MyContainerComponent {
  @ContentChildren(
    MyComponent
  ) components: QueryList<MyComponent>;
}

To me this doesn't seem consistent with the behavior if we, for example, add another decorator. I believe giving a lower cost to splitting between decorator and property should improve consistency.

Reproduction link can be found here.

Metadata

Metadata

Assignees

No one assigned

    Labels

    locked-due-to-inactivityPlease open a new issue and fill out the template instead of commenting.

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions