I am currently working on developing a function that dynamically defines a class extending another class based on a passed object. Here is an example of what I am aiming to achieve:
const ObjectMixin = function<T>(obj: T): new () => T {
return class extends BaseClass {
...obj // pseudo code illustrating the concept
}
}
The purpose of this function is to streamline the process of creating Vue class components with mapped state inclusion. An example implementation would look like this:
class MyComponent extends ObjectMixin(smartModule.mapState(['someState'])) {
created() {
this.someState // should not result in any errors
}
}
I have made some progress using workarounds such as the following:
interface ObjMixinI {
<T>(obj: T): new () => T
}
const ObjectMixin: ObjMixinI = obj =>
//@ts-ignore
function() {
//@ts-ignore
Object.assign(this, obj)
}
However, I am facing challenges in making it extend Vue and acknowledge that this current method is not ideal.