-
Notifications
You must be signed in to change notification settings - Fork 12.8k
[Bug] Mixin parameters failed to use as Method Parameter types of Inner Classes #50792
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weβll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
The error message is correct. |
I know that const register: MethodDecorator = () => { }
const validate: ParameterDecorator = () => { }
function mixin<T>(Model: new (...data: any[]) => T) {
class Trait {
@register
- method(@validate input: Model) { }
+ method(@validate input: typeof Model) { }
}
return Trait;
}
class TestModel {
id = 0
}
class TestController extends mixin(TestModel) { } 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:paramtypes", [Object]),
__metadata("design:returntype", void 0)
], Trait.prototype, "method", null);
return Trait;
} |
I think this workaround should work: function mixin<T>(Model: new (...data: any[]) => T) {
+ type Model = typeof Model;
class Trait {
@register
method(@validate input: Model) { }
}
return Trait;
} |
@whzx5byb Thanks your hack code, but I wonder that |
@whzx5byb If I use both type & value of classes, your hack code shows a type error in my VS Code 1.71.0: - const register: MethodDecorator = () => { }
+ const register: (Model: new (...data: any[]) => any) => MethodDecorator =
() => () => { }
const validate: ParameterDecorator = () => { }
function mixin<T>(Model: new (...data: any[]) => T) {
+ type Model = typeof Model;
class Trait {
- @register
+ @register(Model)
method(@validate input: Model) { }
}
return Trait;
}
class TestModel {
id = 0
}
class TestController extends mixin(TestModel) { }
but TS playground & GitPod's VS Code 1.69.2 works fine, too... |
A class declaration does create value and type entities but a variable only create the value one. In your case
I believe this is a bug, which is similar to #50191 and #50161. I have reported it in #50795. |
const A: new() => any = class B {}
function validate(...a: any[]) {}
class B {
@validate test(a: typeof A) {}
} compiles to It looks like the behavior of |
π Search Terms
mixin, parameter, class method, type declaration, decorator
π Version & Regression Information
β― Playground Link
Playground link with relevant code
π» Code
π Actual behavior
Type checking crashed
Compiled seems to work
π 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
The text was updated successfully, but these errors were encountered: