gertqin / vuex-class-modules

Typescript class decorators for vuex modules
MIT License
193 stars 20 forks source link

@Module decorator does not preserve metadata #9

Closed bodograumann closed 5 years ago

bodograumann commented 5 years ago

After digging into issue #6 a little more, I found the following problem. I have created a simple example in https://github.com/bodograumann/vuex-inject-modules-example.

When defining a class through:

import { decorate, inject, injectable } from "inversify";
import { RegisterOptions, Module, VuexModule } from "vuex-class-modules";

decorate(injectable(), VuexModule);

@injectable()
export default class VuexExampleModule extends VuexModule {
  constructor(@inject("VuexModuleOptions") options: RegisterOptions) {
    super(options);
  }

  get testString() {
    return "foo bar";
  }
}

inversify adds metadata to the class. In particular, calling

Reflect.getMetadata("inversify:tagged", VuexExampleModule);

gives

{ 0: [{ key: "inject", value: "VuexModuleOptions" }] }

Unfortunately, when now applying the @Module decorator as well, the metadata is not there anymore:

[…]
@Module
@injectable()
export default class VuexExampleModule extends VuexModule {
  constructor(@inject("VuexModuleOptions") options: RegisterOptions) {
[…]

Now the above reflection call returns undefined.

bodograumann commented 5 years ago

Maybe the comments in the reflect-metadata readme are relevant.