tannerntannern / ts-mixer

A small TypeScript library that provides tolerable Mixin functionality.
MIT License
379 stars 27 forks source link

mixin mode can't work with decorator #59

Closed flame4 closed 1 year ago

flame4 commented 1 year ago

Hi, @tannerntannern .

Thanks for your fantastic job! I'm happy with that repo!

however, i found there's some issue that ts-mixer doesn't work. the error message is:

MissingReflectMetadata: Could not reflect metadata of type design:type, did you forget to enable "emitDecoratorMetadata" on compiler options?

even I have opened this switch.

i rebuild a repo here which can reproduce this error : https://github.com/flame4/ts-mixer-demo.

Actually i just learned ts for 2 months so i don't know too much underlayer details, please take a look on this repo thanks!

tannerntannern commented 1 year ago

Hi @flame4, thanks for the reprex repo. ts-mixer doesn't use reflect-metadata and has no need for emitDecoratorMetadata to be enabled in the config, unless a sibling package needs it. The error you're seeing is likely due to another dependency, probably typedorm in your case.

I can't comment on what might be causing that error, as I'm not familiar with typedorm. However I did notice in your repo that you should probably wrap the class decorator as well:

-@Entity({
+@decorate(Entity({
  name: "user",
  primaryKey: {
    partitionKey: "USER@{{user_id}}",
    sortKey: "USER@{{user_id}}",
  },
-})
+}))
export class User extends Mixin(T, T2) {}

That's my best guess as to what could be causing the error. But either way it sounds like this error originates outside of ts-mixer so if it doesn't resolve the issue, you'll have to look elsewhere for troubleshooting (unless you can show that this error does actually trace back to ts-mixer).

flame4 commented 1 year ago

OK,thanks for help. @tannerntannern

If ts-mixed doesn't use 'reflect-metadata', then it theoretically can't work since typedorm uses 'reflect-metadata' to add metadata.

The advice you given doesn't work.

However what i can make sure is that typedorm is inspired by typeorm, so the usage of decorator of both should be similar. I notice that the @decorate function is promoted by typeorm's compatibility problem, some issue history like #15 , #7 and #35 , i do think it can works like a AOP injection layers

It makes me confused, i quite think those issue is raised by some same kernel reason...

However let me try more, thanks again.