I want to check for exact types on a discriminated union as follows:
interface Circle {
kind: "circle";
radius: number;
}
interface CircleCustom {
kind: "circle";
radius: number;
customProp1: number;
customProp2: number;
}
interface Square {
kind: "square";
sideLength: number;
}
type Shape = Circle | CircleCustom | Square;
let myCustomCircle: Shape = {
kind: 'circle',
radius: 1,
customProp1: 1,
// missing customProp2, no error is trigered
}
I need the compiler to understand that when the customProp1
is there then the customProp2
must be available as well.
Is there another way to achieve this?