I am trying to create the following interface in typescript:
type MoveSpeed = "min" | "road" | "full";
interface Interval {
min?: number,
max?: number
}
interface CreepPlan {
[partName: string] : Interval;
move?: MoveSpeed;
}
However, this syntax is invalid. The compiler says Property 'move' of type '"min" | "road" | "full" | undefined' is not assignable to string index type 'Interval'..
I am using the compiler option strictNullChecks:true, which is why undefined is included implicitly for the move? key.
However, this syntax is valid:
type MoveSpeed = "min" | "road" | "full";
interface Interval {
min?: number,
max?: number
}
interface CreepPlan {
[partName: string] : Interval;
move: MoveSpeed; // 'move' is required
}
I want to express the idea "CreepPlan consists of string:Interval pairs, except the optional 'move' key which is a string:MoveSpeed pair." Is it possible to express this in typescript?
strictNullChecksset to true. I will clarify.