[Bug] Mixin parameters failed to use as Method Parameter types of Inner Classes
See original GitHub issue🔎 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
Issue Analytics
- State:
- Created a year ago
- Comments:8 (1 by maintainers)
Top Results From Across the Web
tutorial:mixin_examples [Fabric Wiki]
Mixing into a private inner class. Use the targets parameter and a $ sign to get the inner class. @Mixin(targets = ...
Read more >python - How do I correctly add type-hints to Mixin classes?
The code works. But running mypy on it, yields the following errors: example.py:4: error: "MultiplicatorMixin" ...
Read more >How to Use Mixins in Sass and Pass Arguments – With Code ...
"Mixins allow you to define styles that can be re-used throughout your stylesheet. They make it easy to avoid using non-semantic classes ......
Read more >Mixins, Pt.1; Generics, Pt. 1
In the past two weeks, we reviewed classes and interfaces as well as ... by further functionality– which we can do using default...
Read more >The mixin pattern in TypeScript - all you need to know - Bryntum
This error demonstrates how TypeScript prevents us from using arbitrary properties / methods on a variable with the MyMixinType type.
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
@TechQuery
A class declaration does create value and type entities but a variable only create the value one. In your case
Model
is just a variable refers to the class, so it doesn’t create a type entity.I believe this is a bug, which is similar to https://github.com/microsoft/TypeScript/issues/50191 and https://github.com/microsoft/TypeScript/issues/50161. I have reported it in https://github.com/microsoft/TypeScript/issues/50795.
@whzx5byb Thanks your explanation & issue reporting.
When I open my GitPod VS Code again, the same error hints…
Just like #50161 said: sometimes…