TypeScript

Primitive Data Types in TypeScript (React, Angular, Vue, Node.js, and Express)

This is a practical article about Primitive Data Types in TypeScript — especially in the context of frameworks like React, Angular, Vue, Node.js, and Express.

TypeScript, unlike plain JavaScript, introduces static typing. This means you can explicitly declare the type of a variable, parameter, or return value, and the compiler will help catch mistakes before your code runs.

At the foundation of TypeScript are the primitive data types. These are the most basic building blocks for creating type-safe applications, whether you’re working in React, Angular, Vue, or on the backend with Node.js/Express.


What Are Primitive Data Types?

Primitive types represent single values, not objects. They are immutable, meaning once created, they cannot be changed. In TypeScript, the main primitives include:

  1. string
  2. number
  3. boolean
  4. null
  5. undefined
  6. symbol
  7. bigint

Each of these plays an important role in building reliable applications.

The value of primitive is stored in separate ‘box’ in the memory.


1. string

Represents text values enclosed in quotes.

let username: string = "Alice";
let greeting: string = `Hello, ${username}!`;

Use case in frameworks:

  • React: Define component props as strings.
  • Angular/Vue: Bind form inputs to string variables.
  • Node/Express: Parse request parameters (e.g., req.params.id: string).

2. number

Represents integers and floating-point values. TypeScript does not differentiate between int and float.

let age: number = 25;
let price: number = 19.99;

Use case in frameworks:

  • React: Component state counters.
  • Angular/Vue: Numeric form fields.
  • Node/Express: Database IDs or pagination numbers.

3. boolean

Represents logical values: true or false.

let isLoggedIn: boolean = true;
let isAdmin: boolean = false;

Use case in frameworks:

  • React: Toggle UI (dark mode on/off).
  • Angular/Vue: Conditional rendering in templates.
  • Node/Express: Authorization checks.

4. null

A special type that represents no value.
In TypeScript, null is only assignable to variables with the null type or when using union types.

let emptyValue: null = null;
let user: string | null = null;

Use case:

  • Optional fields (e.g., user.middleName: string | null).
  • Resetting state values in React, Angular, or Vue.
  • Clearing session/user data in Node/Express.

5. undefined

Represents a variable that has been declared but not assigned a value.

let notAssigned: undefined = undefined;
let optionalValue: string | undefined;

Use case:

  • Optional props in React.
  • Optional function parameters in Angular services.
  • API responses where a property may or may not exist.

6. symbol

Introduced in ES6, symbol is a unique and immutable identifier.
Useful for creating private or special object keys.

const uniqueKey: symbol = Symbol("id");

Use case:

  • Advanced libraries in React or Angular might use symbols for metadata.
  • Useful in Node.js when creating unique keys in shared objects.

7. bigint

For integers larger than Number.MAX_SAFE_INTEGER (2^53 - 1).

let bigValue: bigint = 123456789012345678901234567890n;

Use case:

  • Handling large numbers in Node.js (e.g., financial systems, crypto).
  • Rare in frontend (React/Angular/Vue), but possible when working with precise calculations.

Quick Reference Table

PrimitiveExampleCommon Use Case
string"Hello"Usernames, form fields, messages
number42Counters, prices, database IDs
booleantrueToggles, flags, conditions
nullnullOptional/resettable values
undefinedundefinedUnassigned variables, optional props
symbolSymbol("id")Unique keys, metadata
bigint123nLarge financial or cryptographic numbers

Primitive Types in Action (React Example)

type UserProps = {
  name: string;
  age: number;
  isAdmin: boolean;
  middleName?: string; // optional (string | undefined)
};

const UserCard: React.FC<UserProps> = ({ name, age, isAdmin, middleName }) => (
  <div>
    <h2>{name} ({age})</h2>
    <p>{isAdmin ? "Admin" : "Regular User"}</p>
    {middleName && <p>Middle name: {middleName}</p>}
  </div>
);

Conclusion

Primitive data types in TypeScript are the foundation of type safety. They prevent many common errors before runtime, no matter whether you’re building:

  • A React UI component with strict prop types.
  • An Angular service with clearly typed parameters.
  • A Vue state store with properly typed data.
  • A Node/Express API with reliable request/response contracts.

By mastering primitives, you set the stage for confidently working with more advanced TypeScript features like unions, intersections, generics, and custom types.


Related posts
TypeScript

Literals in TypeScript: String, Number, Boolean, Template, and Compound Literals

Literals are one of the fundamental building blocks of TypeScript programming. They represent fixed…
Read more
TypeScript

Utility Types in TypeScript: Pick, Omit, Partial, Required, Readonly, Record...

✅ — Utility Types are one of the most powerful features of TypeScript, but also one of the most…
Read more
TypeScript

Complete TypeScript Tutorial Online: Master TypeScript in 2025

TypeScript has revolutionized modern web development by bringing static typing to JavaScript, making…
Read more