CricketScript Lesson 4 of 11 · The player card  |  Course

The player card

Same fields, different player. That’s an interface.

Every player has a card. Every card has the same fields — name, role, jersey, country, strike rate. Aarav Sharma's card and Owen Pretorius' card hold different values, but they have the same shape.

TypeScript calls that shape an interface. You define it once: “a Player must have these fields, with these types.” Then every object you label as a Player has to satisfy that contract. Miss a field, change a type, and the compiler will catch it.

Tap a different player below to swap cards. Then try the × on any field — TypeScript will not let you drop it.

Tap a different player to swap cards.

Aarav Sharma

Right-hand opener · India

jersey 7
strike rate 165
captain true

The interface is a contract.

Define the shape once. Every Player object then has to satisfy it — same fields, same types. Different values are fine; missing fields are not.

interface Player {
  name: string;
  role: string;
  jersey: number;
  strikeRate: number;
  isCaptain: boolean;
}

const player: Player = {
  name: 'Aarav Sharma',
  role: 'Right-hand opener',
  jersey: 7,
  strikeRate: 165,
  isCaptain: true,
};

One shape, many cards.

You just used the Player interface to look at five very different players. Same five fields each time — name, role, jersey, strike rate, captain flag — but the values changed completely. That's what interfaces are for: the shape is a contract, the contents are yours to fill.

When you remove a required field, the compiler stops you cold. When you give a field the wrong type — jersey as a string, isCaptain as a number — it stops you the same way. Interfaces are how TypeScript ensures every Player you build is actually a Player.

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