frankwallis / plugin-typescript

TypeScript loader for SystemJS
MIT License
248 stars 47 forks source link

decorator metadata not working on interface type decorated properties #136

Closed ronzeidman closed 8 years ago

ronzeidman commented 8 years ago

this is how the plugin decorated my component:

__decorate([
        core_1.Input(), 
        __metadata('design:type', (typeof (_c = typeof Observable_1.Observable !== 'undefined' && Observable_1.Observable) === 'function' && _c) || Object)
    ], MainFormLevelRowComponent.prototype, "category$", void 0);
    __decorate([
        core_1.Input(), 
        __metadata('design:type', (typeof (_d = typeof dd_1.ILevel !== 'undefined' && dd_1.ILevel) === 'function' && _d) || Object)
    ], MainFormLevelRowComponent.prototype, "level", void 0);

this is how tsc decorated the component:

    __decorate([
        core_1.Input(), 
        __metadata('design:type', Observable_1.Observable)
    ], MainFormPriceLevelRowComponent.prototype, "category$", void 0);
    __decorate([
        core_1.Input(), 
        __metadata('design:type', Object)
    ], MainFormLevelRowComponent.prototype, "level", void 0);

I have two issues with the first approach: 1) I cannot import typescript interfaces in js and work with them 2) the type interface is from a "contract only" "d.ts" file, and it tried to require it. obviously it didn't work.

Since I use decorators on interface type properties I cannot use this plugin at all.

Thanks for the hard work!

frankwallis commented 8 years ago

This sounds quite strange, are you able to provide a repro?

aluanhaddad commented 8 years ago

@ronzeidman @frankwallis it's impossible to decorate interfaces or there properties because they have no runtime representation. This should actually produce a compilation error. If you're trying to use dependency injection systems that rely on decorator metadata to inject implementations of services you need to use classes.

aluanhaddad commented 8 years ago

Properties with interface types can be decorated in classes they are written in typescript. There's no way to import interfaces into a Javascript file. Make sure the version of typescript used by plugin-typescript and the version you are using in your IDE or from the command line is the same version.

ronzeidman commented 8 years ago

@aluanhaddad I'm not using interfaces for dependency injection, I'm using them just to signify input variables in angular 2 which should be supported:

@Input() myVar: IMyInterface;

This decorator should use "Object" type instead of the interface type since the code of the decorator doesn't actually use the type, "Object" type is sufficient. I'm pretty sure I'm using the same devDependency of typescript in both cases. I'll try to create a simple reproduction and post it here. Sorry for the delay.

ronzeidman commented 8 years ago

In the latest version it works as expected. Sorry for the trouble.