Skip to content

Declaration in @NgModule duplicating when generating stuff #16009

@MetaMoRpheXx

Description

@MetaMoRpheXx

🐞 Bug report

Command (mark with an x)

- [x] generate

Is this a regression?

Probably, found it on version 8.3.5

Description

The "declaration" key in @NgModule duplicating when generating stuff.

🔬 Minimal Reproduction

  1. Put a quotes or a double-quotes on the "declaration" key at any @NgModule. Or set "object-literal-key-quotes" on tslint to [true, "always"]. Originally, it would look like this:
@NgModule({
  declarations: [Component1, Component2],
  imports: [
    CommonModule,
    OtherModule
  ]
})
  1. Run ng lint --fix (if you did the tslint). It should now look like this:
@NgModule({
  "declarations": [Component1, Component2], // ---> added quotes on the "declaration"
  "imports": [
    CommonModule,
    OtherModule
  ]
})
  1. Generate a component where it would import on the said module. It either generates another "declaration" key with or without quotes (depending on your schematics whether you run lint after generating). It would now look like this:
@NgModule({
  "declarations": [Component1, Component2],
  "imports": [
    CommonModule,
    OtherModule
  ]
  "declarations": [Component3] // ---> It would generate this with or without quotes instead of merging it with the existing one
})

🔥 Exception or Error

Running ng serve now throws the error

error TS2300: Duplicate identifier 'declarations'.

Other Notes

Not big of an issue, but it kills some of the tasks that should be automated when you have a custom tslint settings at the same time.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions