Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
Literal('Thursday'),
Literal('Friday'),
Literal('Saturday'),
);
// Extract the static type
type Day = Static; // = 'Sunday' | 'Monday' | 'Tuesday' | 'Wednesday' | 'Thursday' | 'Friday' | 'Saturday'
// Extract enumerated literal values
const days: Day[] = Day.alternatives.map(lit => lit.value);
for (const day of days) {
console.log(`Good morning, it's ${day}!`);
}
const isWeekend = match(
[Literal('Sunday'), () => true],
[Literal('Saturday'), () => true],
[Day, () => false],
);
import { match, Record, Number, Union, Static } from 'runtypes';
const Square = Record({ size: Number });
const Rectangle = Record({ width: Number, height: Number });
const Circle = Record({ radius: Number });
const Shape = Union(Square, Rectangle, Circle);
const area = Shape.match(
({ size }) => Math.pow(size, 2),
({ width, height }) => width * height,
({ radius }) => Math.PI * Math.pow(radius, 2),
);
const hasCorners = match(
[Circle, () => false],
[Union(Square, Rectangle), () => true]
);