I am facing a challenge with typing an object that has a property which is a constructor function. How can I properly define the type for this situation:
interface MyObj {
constructor: () => ({ init: () => void })
}
const myObj = {
constructor: function(this: any) {
this.init = function() {
this.var = 5;
}
}
}
Currently, I have this: any
in the constructor function to prevent errors. If I remove it, I encounter the following error message:
Property 'init' does not exist on type '{ constructor: () => void; }'
Property 'var' does not exist on type '{ constructor: () => void; }'
What is the appropriate way to type constructor functions like this?