Complete the code to define a conditional type that returns 'string' if T is 'string', otherwise 'number'.
type CheckType<T> = T extends [1] ? 'string' : 'number';
The conditional type checks if T extends string. If yes, it returns 'string', otherwise 'number'.
Complete the code to create a distributive conditional type that extracts the element type from an array type.
type ElementType<T> = T extends [1] ? T[number] : T;T[number] to extract element type.The conditional type checks if T extends an array type any[]. If yes, it returns the element type T[number], otherwise returns T itself.
Fix the error in the conditional type that should distribute over union types to return 'true' if T is 'string' or 'number', otherwise 'false'.
type IsStringOrNumber<T> = T extends [1] ? true : false;The conditional type distributes over union types. To check if T is string or number, use string | number in the extends clause.
Fill both blanks to create a conditional type that returns the keys of T whose values extend string.
type StringKeys<T> = { [K in keyof T]: T[K] [1] string ? K : never }[[2]];This mapped type iterates over keys K of T. For each key, it checks if the value type T[K] extends string. If yes, it keeps the key K, otherwise never. Finally, it indexes with keyof T to get a union of keys with string values.
Fill all three blanks to create a distributive conditional type that converts union members to their array types, otherwise returns never.
type ToArray<T> = T extends [1] ? [2][] : [3];
This conditional type checks if T extends unknown (which is always true, triggering distributive behavior). It then converts each member of the union T to an array type T[]. Otherwise, it returns never.