leonardfactory / babel-plugin-transform-typescript-metadata

Babel plugin to emit decorator metadata like typescript compiler

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Enums types with propery decorators are incorrectly transformed

whimzyLive opened this issue · comments

There seems to be some issues around transforming property decorators that has Enum as a type.
Here is what is different:

Given

export function ExampleDecorator(): PropertyDecorator {
  return (target, propertyKey): void => {
   // trying to get type like this
    const type = Reflect.getMetadata('design:type', target, propertyKey);
    console.log(type) 
  };
}

enum DEMO {
  PROP_1 = '1',
  PROP_2 = 2
}
class A {
  @ExampleDecorator()
  stringProp: string

  @ExampleDecorator()
  demoProp: DEMO
}

Here is what is printed to stdout

[Function: String]
{ '2': 'PROP_2', PROP_1: '1', PROP_2: 2 }  // not sure why the type of an enum is converted to this

However, running the same code through tsc, this is what is returned (and I believe is correct)

[Function: String]
[Function: Object]

Reproduction repo:
https://github.com/whimzyLive/incorrect-enum-transform
@leonardfactory do you know something on what might be casuing this difference.

@leonardfactory @wtho sorry to tag you again, can someone point me to an entry point of what might be causing this, I can try looking into it.

Enums are currently not supported, see: #11