I want to be able to extend a base interface at one or more specic locations. The idea is to be able to define a base state for the library xstate which can be extended for more specific purposes.
I have
interface Base {
id:string;
states:{
init:{},
loading:{},
idle:{
states:{
someBaseState:{}
}
}
}
}
I want to know if it is possible with typescript to extend the base interface at a specific location. e.g the "idle" property
interface Page "extends Base Idle Property" {
id:string;
states:{
someOtherState:{}
}
}
so that the result is
{
id:string;
states:{
init:{},
loading:{},
idle:{
id:string;
states:{
someBaseState:{}
someOtherState:{}
}
}
}
}
I know that I can define Generic in Typescript like this
interface Base<T> {
id: string;
states: {
idle: T
}
}
But I want to be able to define specific base properties for the state "idle" (for example) and not completely implement it each time.