Skip to content

Class decorators: extending the constructor of a component's class doesn't get called. #53740

@amerkarim

Description

@amerkarim

Which @angular/* package(s) are the source of the bug?

core

Is this a regression?

No

Description

Adding a new class decorator on top of the Component decorator and extending the the constructor does not work, the constructor is not called.

Adding the same decorator on a regular class works as excepted.

@MyDecorator()
@Component({
  ...
})


function MyDecorator() {
  return <T extends { new (...args: any[]): {} }>(constr: T) => {
    return class extends constr {
      constructor(...args: any[]) {
        super(...args);
        console.log('Inside the extended constructor.'); //This is not called
      }
    };
  };
}

Please provide a link to a minimal reproduction of the bug

https://stackblitz.com/edit/node-khhnqm?file=src%2Fapp%2Fapp.component.ts

Please provide the exception or error you saw

No errors.

Please provide the environment you discovered this bug in (run ng version)

Angular CLI: 17.0.8
Node: 18.16.1
Package Manager: npm 8.12.1
OS: win32 x64

Angular:
...

Package                      Version
------------------------------------------------------
@angular-devkit/architect    0.1700.8 (cli-only)
@angular-devkit/core         17.0.8 (cli-only)
@angular-devkit/schematics   17.0.8 (cli-only)
@schematics/angular          17.0.8 (cli-only)

Anything else?

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions