Turns out you can define types conditionally based on the a 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:17 Utility Types in the handbook
  • 01:30 Function setup
  • 02:58 Parameters and ReturnType
  • 06:39 Class setup
  • 07:30 ConstructorParameters and InstanceType
  • 11:10 Outroduction

Utility Types page: https://www.typescriptlang.org/docs/handbook/utility-types.html#parameterstype
Code: https://github.com/jherr/no-bs-ts/tree/master/episode-19

#typescript

Utility Types in Typescript - Part 2 - No BS TS #19
1.80 GEEK