Open
Description
π Search Terms
mixin, parameter, class method, type declaration, decorator
π Version & Regression Information
- This is a crash
- This is the behavior in every version I tried, and I reviewed the FAQ for entries about mixin & parameter
β― Playground Link
Playground link with relevant code
π» Code
const register: MethodDecorator = () => { }
const validate: ParameterDecorator = () => { }
function mixin<T>(Model: new (...data: any[]) => T) {
class Trait {
@register
method(@validate input: Model) { }
}
return Trait;
}
class TestModel {
id = 0
}
class TestController extends mixin(TestModel) { }
π Actual behavior
Type checking crashed
error TS2749: 'Model' refers to a value, but is being used as a type here. Did you mean 'typeof Model'?
method(@validate input: Model) {
~~~~~
Compiled seems to work
function mixin(Model) {
var _a;
class Trait {
method(input) { }
}
__decorate([
register,
__param(0, validate),
__metadata("design:type", Function),
__metadata("design:paramtypes", [typeof (_a = typeof Model !== "undefined" && Model) === "function" ? _a : Object]),
__metadata("design:returntype", void 0)
], Trait.prototype, "method", null);
return Trait;
}
π Expected behavior
Shown sample code works, so that projects with Decorator frameworks will be much simpler, like what my service scaffold does: idea2app/REST-Node-ts#1