CricketScript Lesson 5 of 11 · Pick your bowler  |  Course

Pick your bowler

Three styles. Only three. The captain picks one.

Cricket bowlers come in styles, and only a few of them. Fast rips through with pace. Spin loops the ball into the surface and asks it to turn. Medium is the workhorse — neither express nor tweaker, somewhere in between. There is no fourth thing called ‘mostly-fast’ or ‘sort-of-spin’.

TypeScript has a type for that. A union of literal types lists the only allowed values: 'fast' | 'spin' | 'medium'. Any string outside that set won't compile. The captain — and the type system — pick from a closed list.

Tap a style below. Then try the red button to pick a style that doesn't exist — the umpire will explain why it isn't allowed.

Pick a bowling style.
VS AS

Three options, in one type.

The pipe symbol (|) means “or”. The whole type means “one of these three strings, and no others.”

type BowlerStyle = 'fast' | 'spin' | 'medium';

const style: BowlerStyle = 'fast';
// captain's pick — the union enforces it

// TypeScript would catch this:
// const wrong: BowlerStyle = 'mostly-fast';
//   // Type '"mostly-fast"' is not assignable to
//   // type 'BowlerStyle'.

A union is a closed list.

BowlerStyle can hold only 'fast', 'spin', or 'medium'. Try assigning any other string and TypeScript stops you at compile time — no ‘mostly-fast’, no typos, no surprises in production.

Use a union of literal types whenever the answer comes from a fixed set of options — bowler styles, payment statuses, traffic-light colours, anything where ‘something else’ would be a bug.

Lesson 6 — Bowl one →
Reading a paid lesson? The rest is right here.

This is one of 9 paid lessons. Lessons 1 and 9 are free previews if you want to sample first — otherwise the full course unlocks in one click.

$15worldwide · ₹625India (50% off)
Unlock all 11 lessons + bonus →
30-day money-back guarantee · Try Lessons 1 and 9 free first if you'd rather
Made by one person, not a company. Questions: hello@cricketscript.dev