Skip to main content

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

  1. string - a string Used for text data.
javascript
let name: string = "Tim";
  1. number - a number Covers both integer and fractional values (all numbers are floating-point).
javascript
let age: number = 25; let price: number = 19.99;
  1. boolean - a boolean value (true/false)
javascript
let isOnline: boolean = true;
  1. bigint - an integer of arbitrary length (ES2020+) Used when you need to work with very large numbers.
javascript
let big: bigint = 123456789012345678901234567890n;
  1. symbol - a unique identifier (ES2015+) Guarantees the uniqueness of a value, often used as an object key.
javascript
const id: symbol = Symbol("id");
  1. undefined - the "not defined" value Usually means that a variable is declared but has no value.
javascript
let value: undefined = undefined;
  1. null - the intentional absence of a value
javascript
let empty: null = null;

  1. void - "returns nothing" Used as the type of a function that returns no value.
javascript
function logMessage(): void { console.log("Hello"); }
  1. 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!"); }
  1. unknown - an "unknown type" A safe alternative to any. Requires a check before use.
javascript
let data: unknown = "Hello"; if (typeof data === "string") { console.log(data.toUpperCase()); }
  1. any - "any type" Turns off type checking (used rarely and carefully).
javascript
let something: any = 123; something = "text"; // allowed

Summary:

CategoryTypes
Primitivestring, number, boolean, bigint, symbol, null, undefined
Special utilityvoid, never, unknown, any

Short Answer

Interview ready
Premium

A concise answer to help you respond confidently on this topic during an interview.