I write a library
type State = {
playing: boolean
phases: {
[key: string]: {
progress: number
}
}
}
class BaseWidget {
state: State
constructor() {
this.state = {
playing: false,
phases: {},
}
}
}
I use it like this
class Widget extends BaseWidget {
constructor() {
super()
this.state.phases = {
start: {
progress: 0,
},
finish: {
progress: 0,
},
}
}
}
Different classes of inherited BaseWidget have different phases
How can I specify that this Widget class will only have a start and a finish?
Is it possible to somehow clarify the State type from the Widget class?
Or maybe I need to use generics?
Maybe I need to use not [key: string], but [key in keyof T]? But how do I pass T? What is the correct syntax?
Thanks!