CricketScript Lesson 8 of 11 · Runs are limited  |  Course

Runs are limited.

Off a single ball, only certain run totals are legal.

Cricket's scoring grammar is strict. From one delivery, the batters can run a single, a double, a triple — rare but possible — strike a boundary four, or clear the rope for six. Five is impossible. Seven is impossible. The scorebook simply has no slot for them.

A type alias gives that grammar a name. type Run = 0 | 1 | 2 | 3 | 4 | 6 tells TypeScript: any value in this rule must be one of those six numbers. Try to record a 5 or a 7, and the compiler refuses — at write time, not at the scorer's desk.

Tap a legal run to log it. Tap an illegal one to see TypeScript catch the impossible.

Tap a value to record off this ball.
striker non-striker
Score
0/0
 

Six legal values. The compiler knows.

A type alias is a reusable name for a type expression. Here, Run is a union of six literal numbers — the only values TypeScript will accept.

type Run = 0 | 1 | 2 | 3 | 4 | 6;

function record(r: Run): void { /* ... */ }

record(1);   // ok — quick single
record(4);   // ok — through the covers
record(6);   // ok — over the rope

record(5);  // Argument of type '5' is not assignable
            // to parameter of type 'Run'.
record(7);  // Same — 7 isn't in the union either.

Name a grammar. Reuse it.

type Run is a label for "the only values that can come off a single ball." Once the alias exists, every function that takes a Run shares the same guarantee — and every misuse is caught the moment it's typed.

Type aliases shine when a shape repeats: positions on a field, sides of a coin, suit of a card. Name the shape once. TypeScript polices it everywhere.

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