TypeScript Expert

Preview — 3 of 10 questions

What is the inferred type of result?

javascript
type Concat<T extends unknown[], U extends unknown[]> = [...T, ...U];
type Result = Concat<[string, number], [boolean, null]>;
A(string | number | boolean | null)[]
B[string, number, boolean, null]
C[string | number, boolean | null]
Dunknown[]

What does this recursive type represent?

javascript
type NestedArray<T> = T | NestedArray<T>[];
AAn array that can only contain one level of nesting
BA union of all array types
CA value that is either T or an arbitrarily deeply nested array of T
DThis is a TypeScript error — recursive types are not allowed

In TypeScript, a ReadonlyArray<T> is covariant in T. What does this mean?

javascript
class Animal { name = "animal" }
class Dog extends Animal { breed = "labrador" }

const dogs: ReadonlyArray<Dog> = [new Dog()];
const animals: ReadonlyArray<Animal> = dogs; // ✅ covariance — safe

// This is safe because ReadonlyArray is read-only:
// You can only READ from it, never write.
// Reading a Dog as an Animal is always safe.
AReadonlyArray<Animal> is a subtype of ReadonlyArray<Dog> if Dog extends Animal
BReadonlyArray<Dog> is a subtype of ReadonlyArray<Animal> if Dog extends Animal
CReadonlyArray<T> does not participate in subtyping at all
DReadonlyArray<Dog> and ReadonlyArray<Animal> are always the same type

Sign up free to play

Answer all 10 questions (7 more), see explanations for every answer, and track your score.