TypeScript Version: 2.1.1
Flags: emitDecoratorMetadata: true
Code
classSomeArg{}functionSomeDecorator(): any{}
@SomeDecorator()classParent{constructor(a: SomeArg){}}
@SomeDecorator()classChildextendsParent{}Expected behavior:
Does not emit __metadata('design:paramtypes', []) for Child or declares the parameters from the parent class, as Child did not declare an own constructor so the constructor of the parent class gets inherited.
I.e.
Parent = __decorate([
SomeDecorator(),
__metadata("design:paramtypes", [SomeArg])
], Parent);
...
Child = __decorate([
SomeDecorator(),
], Child);
Actual behavior:
Emits __metadata('design:paramtypes', []) as part of the decorators for Child. This is wrong as the the constructor is inherited so Child actually takes one argument of type SomeArg, in contrast to the value of __metadata('design:paramtypes', []).
I.e.
Parent = __decorate([
SomeDecorator(),
__metadata("design:paramtypes", [SomeArg])
], Parent);
...
Child = __decorate([
SomeDecorator(),
__metadata("design:paramtypes", [])
], Child);
** Other notes
It would be really nice to be able to turn on flags as well as choose the typescript version in the typescript playground, so I could post a working reproduction here.
** Workaround
To detect that a class did not declare its own constructor we can use a regex on Child.toString():
const DELEGATE_CTOR = /^function\s+\w+\(\)\s*{\s*(return\s+)?\w+\.apply\(this,\s*arguments\)/;
function isDelegateCtor(ctor: any) {
return DELEGATE_CTOR.exec(ctor.toString());
}
Note that this workaround also works with minified code as none of function / apply / arguments can be minified.
TypeScript Version: 2.1.1
Flags:
emitDecoratorMetadata: trueCode
Expected behavior:
Does not emit
__metadata('design:paramtypes', [])forChildor declares the parameters from the parent class, asChilddid not declare an own constructor so the constructor of the parent class gets inherited.I.e.
Actual behavior:
Emits
__metadata('design:paramtypes', [])as part of the decorators forChild. This is wrong as the the constructor is inherited soChildactually takes one argument of typeSomeArg, in contrast to the value of__metadata('design:paramtypes', []).I.e.
** Other notes
It would be really nice to be able to turn on flags as well as choose the typescript version in the typescript playground, so I could post a working reproduction here.
** Workaround
To detect that a class did not declare its own constructor we can use a regex on
Child.toString():Note that this workaround also works with minified code as none of
function/apply/argumentscan be minified.