Hint
TypeScript conditional types resolve at compile time based on type relationships, not runtime values. The T extends any[] check uses structural compatibility — a type is "array-like" if it extends any[].
// Simulate TypeScript conditional type resolution at runtime
// type IsArray<T> = T extends any[] ? "yes" : "no"
function isArray(val) {
return Array.isArray(val) ? 'yes' : 'no';
}
// TypeScript resolves these at compile time:
// IsArray<number[]> => "yes"
// IsArray<string> => "no"
// IsArray<string[]> => "yes"
// IsArray<null> => "no"
console.log(isArray([1, 2, 3])); // number[]
console.log(isArray('hello')); // string
console.log(isArray(['a', 'b'])); // string[]
console.log(isArray(null)); // null
console.log(isArray({})); // objectyes no yes no no
Explanation: Array.isArray mirrors what TypeScript's conditional type T extends any[] ? "yes" : "no" would resolve to. Arrays satisfy the condition; all other types do not.
Key Insight: TypeScript conditional types resolve at compile time based on type relationships, not runtime values. The T extends any[] check uses structural compatibility — a type is "array-like" if it extends any[].