class BaseComponent {
constructor(props) {
this.data = this.constructor.data(props)
}
}
class MyComponent extends BaseComponent {
static data = ({ message = 'Hello World' }) => ({
message,
color: 'black'
})
}
const gg = new MyComponent({
/* need types */
message: 'Hello from MyComponent'
})
console.log(/* need types */ gg.data)
class BaseComponent<T> {
data: T
constructor(props: T) {
this.data = props
}
}
interface IExample {
text: string
num: number
obj: object
}
class MyComponent extends BaseComponent<IExample> {
data:IExample ={
text:'',
num:1,
obj:{}
}
}
const gg = new MyComponent({
text:'',
num:1,
obj:{}
})
console.log(gg.data)