What is a Conditional Type?
This lesson will teach you how to use and create a conditional type.
We'll cover the following...
We'll cover the following...
A little background on the conditional type
TypeScript 2.8 brings the possibility of the conditional type. The conditional type creates a type by checking if an interface or an existing type extends a type or not. It uses the ternary operator (?:) to get the final type.
Using the conditional type with the dynamic number type
The following code shows a function on line 10 that takes a type T for a parameter. The generic T extends a union of two types defined on lines 1 and 5.
The function returns the object itself and puts the educational goal on the front instead. What is important is the return type on line 10: a type that uses the ...