BeginnerCoder

Lesson 8 — Type aliases

Give a type a name

A type alias (type Name = …) gives a reusable name to any type: a union, an object shape, a function type. Instead of repeating string | number everywhere, you write ID once and use it, so changing it later is one edit.

type Point = { x: number; y: number };
type Status = "open" | "closed";
const s: Status = "open";

Why it matters: good type names make code read like a description of your data.

Want it another way?
Task

Create the ID type (string or number) and make show return "#" + id. Expect #1, then #x7.

Run your code — when the output matches the task, you will see a green check. Then mark the lesson complete.

← Back
Next →
Test your knowledge

A quick 3-question quiz on this lesson — instant feedback.

Enjoying this lesson? Share it.