TypeScript: Conditional Types Explained

Conditionals in TypeScript, also introduced in the TypeScript handbook, allow us to deterministically define types depending on what parameterised types consist of. The general basic rule is:

type ConditionalType = T extends U ? X : Y

--

--

--

Programmer and Author. Director @ JKRBInvestments.com. Creator of LearnChineseGrammar.com for iOS and Android.

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

Types, Type Systems and TypeScript

Angular 11+ Universal Firebase Deployment

Event Listeners

Improve your Vue.js project performance using Nuxt.js

React Native E2E Testing With Appium — Part 1: Why Appium?

Adding TypeScript to an existing Vue CLI project.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Ross Bulat

Ross Bulat

Programmer and Author. Director @ JKRBInvestments.com. Creator of LearnChineseGrammar.com for iOS and Android.

More from Medium

In-Depth Look at TypeScript Generics: Part 2 — Advanced Inference

The Array Prototype Naming Convention

TypeScript 4  — Introduction

Brief Intro to TypeScript Generics