I recently released a 45-seconds YouTube video on conditional types, check my reddit profile for it. I need your feedback before I double down. Let me know what you think. Here is the script:
> Conditional types
In JavaScript, you have a conditional operator:
const ternary = typeof 'Wasim' === 'string' ? true : false console.log(ternary) // true
It is also known as ternary operator.
Similarly, In TypeScript, you also have a conditional operator for types:
type Ternary = 'Wasim' extends string ? true : false // true
This is refer to as a conditional type.
Conditional types allow us to conditionally check for types that match certain criteria and decide what to do if they do match those criteria and what to do if they don’t.
Here is one example:
type Generic<T> = T extends string ?…