Turns out you can define types conditionally based on the type check against a different type. Let’s try it out on a fetch function that optionally takes a callback and can return either a void or a promise based on that callback.

  • 00:00 Introduction
  • 00:18 What are conditional types?
  • 02:15 Importing libraries
  • 03:15 fetchPokemon with conditionals
  • 08:23 fetchPokemon with overloading
  • 11:14 Outroduction

Conditional Types page: https://www.typescriptlang.org/docs/handbook/2/conditional-types.html
Code: https://github.com/jherr/no-bs-ts/tree/master/episode-18

#typescript

Conditional Types in Typescript - No BS TS #18
1.75 GEEK