Primitive types
TypeScript has several primitive types, which are the basic building blocks of the language (that is, not objects and with no methods except the built-in ones via the prototype). Here is the full list:
Main primitive types
string- a string Used for text data.
javascript
let name: string = "Tim";number- a number Covers both integer and fractional values (all numbers are floating-point).
javascript
let age: number = 25;
let price: number = 19.99;boolean- a boolean value (true/false)
javascript
let isOnline: boolean = true;bigint- an integer of arbitrary length (ES2020+) Used when you need to work with very large numbers.
javascript
let big: bigint = 123456789012345678901234567890n;symbol- a unique identifier (ES2015+) Guarantees the uniqueness of a value, often used as an object key.
javascript
const id: symbol = Symbol("id");undefined- the "not defined" value Usually means that a variable is declared but has no value.
javascript
let value: undefined = undefined;null- the intentional absence of a value
javascript
let empty: null = null;Special (not quite primitive, but closely related)
void- "returns nothing" Used as the type of a function that returns no value.
javascript
function logMessage(): void {
console.log("Hello");
}never- "never happens" Used for functions that never complete successfully (for example, they throw an error or loop forever).
javascript
function fail(): never {
throw new Error("Error!");
}unknown- an "unknown type" A safe alternative toany. Requires a check before use.
javascript
let data: unknown = "Hello";
if (typeof data === "string") {
console.log(data.toUpperCase());
}any- "any type" Turns off type checking (used rarely and carefully).
javascript
let something: any = 123;
something = "text"; // allowedSummary:
| Category | Types |
|---|---|
| Primitive | string, number, boolean, bigint, symbol, null, undefined |
| Special utility | void, never, unknown, any |
Short Answer
Interview readyPremium
A concise answer to help you respond confidently on this topic during an interview.