MediumConditional Types💻 Output Question

IsArray conditional — resolves based on type check

💡

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[].

What does this output?

// 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({}));          // object

Correct Output

yes
no
yes
no
no

Why this output?

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[].

More Conditional Types Output Questions

MediumNonNullable conditional — null and undefined are removedHardinfer extracts the wrapped type from a generic containerHardDistributive conditional — union members resolved independently

Practice predicting output live →

66 output questions with instant feedback

💻 Try Output Quiz