Basically I'm trying to create a function that dynamically defines class that extends another class from passed object. Something like this:
const ObjectMixin = function<T>(obj: T): new () => T {
return class extends BaseClass {
...obj // pseudo code to convey the idea
}
}
Goal of this is to be able to write Vue class components with mapped state mixed in. Like this:
class MyComponent extends ObjectMixin(smartModule.mapState(['someState'])) {
created() {
this.someState // should not give any errors
}
}
I almost got it working with hacks
interface ObjMixinI {
<T>(obj: T): new () => T
}
const ObjectMixin: ObjMixinI = obj =>
//@ts-ignore
function() {
//@ts-ignore
Object.assign(this, obj)
}
But I can't make it extend Vue plus it's obviously a horrible solution.
smartModule