Sequence NODE_175
MediumCreate a Discriminated Shape Union
TypeScript
Technical Specification
Create a Shape union type for 'circle' and 'rectangle', each with appropriate fields.
Input/Output Samples
Input:Shape
Output:Circle or Rectangle with strong typing
Optimal Logic Path
type Circle = {
kind: "circle";
radius: number;
};
type Rectangle = {
kind: "rectangle";
width: number;
height: number;
};
type Shape = Circle | Rectangle;Architectural Deep-Dive
Using a discriminant key allows safe narrowing based on kind in switch statements.