I am looking to achieve something similar to the following:
interface StateItem<T extends StateItemType>{
id: string;
values: {
[key in keyof T]: Provider<corresponding typeof T>
}
}
type Primitive = number | string | Position;
interface StateItemType {
[key: string] : Primitive;
}
interface Mover extends StateItemType {
center: Position;
speed: number;
vector: Position;
accruedVector: Position;
}
const mover : StateItem<Mover> = {
id: "123",
values: {
center: createRandomPosition(),
speed: createRandomNumber(),
vector: createRandomPosition(),
accruedVector: createRandomPosition(),
}
}
In essence, I want an interface T
that represents a simple key:type mapping. When creating a StateItem<T>
, all instances of it should include a values
object containing all those keys and Provider<type>
instances.
Could someone provide guidance on how I can achieve this?