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.

Conditional Types | TypeScript Mastery lesson | BraveProgrammer
  1. Courses
  2. /
  3. TypeScript Mastery

Lesson 12 of 56

·Typescript

Conditional Types

20 minutes

Course progress21%

Conditional Types Syntax

type IsString<T> = T extends string ? true : false;
type Test1 = IsString<number>; // false
  = <>; 
type
Test2
IsString
"hello"
// true

Distributive Conditional Types

When the checked type is a union, the conditional distributes over each member.

type ToArray<T> = T extends any ? T[] : never;
type Arr = ToArray<string | number>; // (string[] | number[])

infer Keyword – extracting types

type ReturnType<T> = T extends (...args: any[]) => infer R ? R : never;
type Func = (x: number) => boolean;
type R = ReturnType<Func>; // boolean

Practical Example – DeepPartial

type DeepPartial<T> = {
  [K in keyof T]?: T[K] extends object ? DeepPartial<T[K]> : T[K];
};

Info

Conditional types enable type-level programming; use them sparingly to keep code readable.
Make it stickPractice what you've learned1 quiz · 3 practical tests · Optional activities from TypeScript MasteryBrowse activities
Previous lessonMapped Types & `keyof`Continue to lesson 13Utility Types – `Partial`, `Pick`, `Omit`, `Readonly`Back to TypeScript Mastery curriculum