1. Introduction
TypeScript builds directly on top of JavaScript's primitive types and adds static checking around them. The core primitives you will use daily are string, number, and boolean, alongside null, undefined, bigint, and symbol.
Cricket analogy: Just as cricket has a fixed set of dismissal types — bowled, caught, LBW, run out — TypeScript has a fixed set of primitives like string, number, and boolean that every value must conform to for static checking.
Understanding how TypeScript models each primitive — and where it diverges from other typed languages — is essential before moving on to arrays, objects, and more advanced type constructs.
Cricket analogy: Before analyzing complex data like a full team's season statistics, you first need to know how individual numbers like strike rate and booleans like 'isOut' are represented, the way TypeScript grounds primitives first.
2. Syntax
let str: string = "hello";
let num: number = 42;
let flag: boolean = true;
let big: bigint = 100n;
let sym: symbol = Symbol("id");
let u: undefined = undefined;
let n: null = null;3. Explanation
3.1 string
The string type represents textual data, written with single quotes, double quotes, or backticks (template literals). It covers everything from single characters to entire documents.
Cricket analogy: A commentator's description of the pitch report, the player's name, or the ground's name are all string values in TypeScript, whether written as 'Lord's', "MCG", or a template literal like ` ${venue} Stadium `.
3.2 number
The number type represents all numeric values — integers, floating-point numbers, hex, octal, and binary literals all share the single number type.
Cricket analogy: A batter's strike rate, an over count, and a hexadecimal jersey-color code all share the single number type in TypeScript, whether written as 142.5, 20, or 0x1F.
Unlike languages such as Java or C++, TypeScript has no separate int, float, or double type. Every numeric value — whole or fractional — is typed as number, backed by JavaScript's IEEE 754 double-precision floating point representation. For integers beyond Number.MAX_SAFE_INTEGER, use the distinct bigint type instead.
3.3 boolean
The boolean type has exactly two values: true and false. It is commonly used for flags and conditional logic.
Cricket analogy: Whether a batter isOut has exactly two possible values, true or false, and umpires use this kind of flag constantly, just like TypeScript's boolean type for conditional decisions.
3.4 null, undefined, bigint, and symbol
undefined represents a variable that has been declared but not assigned a value; null represents an intentional absence of value. bigint represents arbitrarily large integers using the n suffix (e.g. 123n). symbol produces unique, immutable identifiers often used as object property keys.
Cricket analogy: A newly created but not-yet-filled 'manOfTheSeries' field is undefined, an abandoned match's result is deliberately null, a career run total might need bigint for astronomical aggregate stats, and a symbol could uniquely key a player's internal record.
By default, unless strictNullChecks is enabled in tsconfig.json, null and undefined are assignable to every type, silently defeating type safety. Always enable strict mode (which includes strictNullChecks) so that a string variable cannot accidentally hold null.
4. Example
let title: string = "TypeScript Basics";
let price: number = 19.99;
let quantity: number = 3;
let inStock: boolean = true;
let total: number = price * quantity;
console.log(`${title}: $${total.toFixed(2)}`);
console.log(`In stock: ${inStock}`);
console.log(typeof price, typeof quantity);5. Output
TypeScript Basics: $59.97
In stock: true
number number6. Key Takeaways
- TypeScript's core primitives are string, number, and boolean.
- There is only one numeric type,
number— no separate int/float/double. - Use
bigint(suffixn) for integers beyond the safe integer range. nullandundefinedare distinct types that should be checked withstrictNullChecksenabled.symbolcreates unique values, typically used as non-colliding object keys.typeofat runtime reports"number"for every numeric value, integer or decimal.
Practice what you learned
1. Which of the following is NOT a separate primitive type in TypeScript?
2. What does `typeof 3.14` and `typeof 42` both return in TypeScript at runtime?
3. How do you write a bigint literal for the value one hundred?
4. What compiler option prevents `null` from being silently assignable to a `string` variable?
5. What is a defining property of the `symbol` type?
Was this page helpful?
You May Also Like
Type Annotations in TypeScript
How to explicitly declare the type of a variable, parameter, or return value using TypeScript's colon syntax.
Arrays in TypeScript
How to type homogeneous lists of values using the T[] and Array<T> syntaxes, including multi-dimensional and readonly arrays.
any, unknown, never and void in TypeScript
The four special types that sit outside normal type checking — the unsafe escape hatch, the safe escape hatch, the impossible type, and the absent-return type.
Type Inference in TypeScript
How TypeScript figures out types automatically from values, without explicit annotations.
Related Reading
Related Study Notes in Programming
Browse all study notesApache Spark Study Notes
Programming · 30 topics
ProgrammingApache Flink Study Notes
Programming · 30 topics
ProgrammingHadoop Study Notes
Programming · 30 topics
ProgrammingSnowflake Study Notes
Programming · 30 topics
ProgrammingApache Airflow Study Notes
Programming · 30 topics
Programmingdbt (Data Build Tool) Study Notes
Programming · 30 topics