Bowl one
A function takes inputs. A bowler takes a speed and a length.
A bowler doesn't just have pace — they have a plan. A delivery is described by two things: how fast (speed in km/h), and where it lands (the length). Fast and short is a bouncer. Slow and full is flighted. A yorker lands at the batter's feet whatever the pace.
TypeScript handles that with multiple parameters. The signature bowl(speed: number, length: Length): string names each input and its type. Pass them in order. Skip one, or pass the wrong type, and the compiler stops you before you ever bowl.
Set a speed and pick a length below, then press Bowl. Watch the ball arrive and the function return its verdict.
Two parameters, one contract.
bowl takes a number and a Length, returns a string. Both arguments are required, and each is checked against its declared type.
type Length = 'short' | 'good' | 'yorker'; function bowl(speed: number, length: Length): string { const pace = speed < 120 ? 'Slow' : speed < 140 ? 'Medium' : speed < 150 ? 'Fast' : 'Express'; return `${pace} ${length}`; } bowl(130, 'good'); // 'Medium good' // TypeScript would catch this: // bowl(140); // Expected 2 arguments, but got 1.
Two parameters, one signature.
You just called a function with two arguments. Speed had to be a number. Length had to be one of four strings (a union from last lesson). The signature bowl(speed: number, length: Length): string guarantees all three — both parameter types and the return type.
TypeScript validates each argument independently: pass a string where a number's expected, or forget an argument entirely, and the compiler stops you before the code ever runs. Functions with multiple parameters describe richer behaviours — a delivery isn't just speed, it's speed and length, like a function.