Skip to main content
Brave Programmer Logo

BraveProgrammer

BraveProgrammer

HomeProjectsBlogsCoursesLessonsAbout

Site footer

BraveProgrammer

Free coding courses, practical tutorials, and real projects from BraveProgrammer. Learn web development with React, Next.js, and TypeScript.

Navigation

  • Home
  • Projects
  • Blogs
  • Courses

Resources

  • About
  • Lessons

© 2026 BraveProgrammer. All rights reserved.

  1. Courses
  2. /
  3. TypeScript Mastery

Lesson 3 of 56 · Typescript

Primitive Types & Type Inference

Duration: 15 minutes

Primitive Types

TypeScript adds static types on top of JavaScript’s primitives.

let isReady: boolean = true;
let count: number = 42;
let name: string = "Alice";
let bigInt: bigint = 9007199254740991n;
let unknownVal: unknown = "maybe";

Type Inference

When you omit an explicit annotation, TypeScript infers the type from the initializer.

let inferred = 123; // inferred as number
let message = "hello"; // inferred as string

If you try to assign a value of a different type, the compiler will error:

inferred = "oops"; // ❌ Type 'string' is not assignable to type 'number'

The any type

let anything: any = 5;
anything = "now a string"; // OK, but you lose type safety.

Best practice: Avoid any; prefer unknown when you truly don’t know the shape.

Info

strictNullChecks (enabled by strict) forces you to handle null and undefined explicitly.

Previous: The TypeScript Compiler & tsconfig.jsonNext: Union & Intersection Types