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
  • Teach on BraveProgrammer

© 2026 BraveProgrammer. All rights reserved.

Primitive Types & Type Inference | TypeScript Mastery lesson | BraveProgrammer
  1. Courses
  2. /
  3. TypeScript Mastery

Lesson 3 of 56

·Typescript

Primitive Types & Type Inference

15 minutes

Course progress5%

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.
Make it stickPractice what you've learned1 quiz · 3 practical tests · Optional activities from TypeScript MasteryBrowse activities
Previous lessonThe TypeScript Compiler & tsconfig.jsonContinue to lesson 4Union & Intersection TypesBack to TypeScript Mastery curriculum