Complete the code to define a type that returns 'string' if T is a string, otherwise 'number'.
type CheckType<T> = T extends [1] ? 'string' : 'number';
The conditional type checks if T extends string. If yes, it returns 'string', else 'number'.
Complete the code to create a type that returns 'true' if T is assignable to number, otherwise 'false'.
type IsNumber<T> = T extends [1] ? true : false;The conditional type checks if T extends number. If yes, it returns true, else false.
Fix the error in the conditional type that should return 'Array' if T is an array, else 'NotArray'.
type CheckArray<T> = T extends [1] ? 'Array' : 'NotArray';
To check if T is an array type, use any[] in the conditional type.
Fill both blanks to create a conditional type that returns the element type if T is an array, otherwise T itself.
type ElementType<T> = T extends [1] ? [2] : T;
Array instead of any[] in condition.The type checks if T is an array (any[]). If yes, it returns the element type using T[number], else returns T.
Fill all three blanks to create a conditional type that returns 'string' if T is string, 'number' if T is number, otherwise 'unknown'.
type TypeName<T> = T extends [1] ? 'string' : T extends [2] ? 'number' : [3];
any instead of 'unknown' in the else case.This conditional type checks if T is string, then returns 'string'. Else if T is number, returns 'number'. Otherwise, returns 'unknown'.