Course contentsShow
← TypeScript
Lesson 93 of 1,7963. Basic TypesFree lesson

Literal Values vs Type Names

Distinguish between the value 42 and the type number, avoiding common beginner mistakes.

Literal Values vs Type Names

You'll learn: How to distinguish between an actual value like 42 and the type number in TypeScript.

The Core Distinction

When you write code, you're juggling two different worlds: values (the actual data) and types (the categories that describe the data). This is one of the most common sources of confusion for beginners.

A value is the concrete data itself: 42, "hello", true. These are things your program works with at runtime.

A type is the category or classification: number, string, boolean. These are TypeScript's compile-time labels that describe what kind of value you're working with.

The Rookie Mistake

Beginners often mix these up when writing type annotations:

let age: 25 = 25; // ❌ Wrong! 25 is a value, not a type
let age: number = 25; // ✅ Correct! number is the type

In the first line, you're trying to use the literal value 25 where TypeScript expects a type name. The second line correctly uses number (the type) to describe what kind of value age can hold.

Think of It Like Labels and Items

Imagine organizing a warehouse. The value is the actual box of goods (the literal 42 apples). The type is the category label on the shelf (number of apples). You don't label a shelf with a specific box—you label it with what kind of boxes belong there.

let count: number = 42; // "number" is the shelf label, 42 is what's in the box

Key Takeaway: Values like 42 are the data your code manipulates; types like number are TypeScript's way of describing what category that data belongs to. Never use a literal value where a type annotation is expected.