Skip to content

Constructor parameter decorator: "propertyKey" is undefined #20931

@thomas-mindruptive

Description

@thomas-mindruptive

TS 2.6.2
Runtime environment: node.js 8.9.0, current Browsers

I'm trying to decorate a constructor parameter with a decorator like this:

export function inject<T>(key?: string | ClassInterface<T> | undefined) {
    ...

    return function (target: Object, propertyKey: string | symbol, paramInx: number): any {
        ...
    }
}

Expected behaviour: "propertyKey" should be defined

Actual: It is undefined

I know that this is similar to #15904. The point there is that this feature depends on the ES property declaration proposal. But I would like to reiterate that:

  • At the moment there is no way of attaining the parameter names of ctors.
  • This would make various dependcy injection scenarios much easier.
  • The transpiler is the only place to get ahold of this design time information. There are no good work-arounds.
  • Even if it is not yet defined in the ES6 proposal: Isn't that what TS is about? Bringing new, useful features to the table and eventually - as ES supports them - transpile them to ES?

Thanks a lot

Metadata

Metadata

Assignees

No one assigned

    Labels

    DuplicateAn existing issue was already created

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions