TypeScript generics vocabulary

  • T (type parameter) — a placeholder replaced with a concrete type at the call/usage site; TypeScript infers it from arguments
  • Array<T> = T[] — equivalent; an array whose elements are all of type T
  • Promise<T> — a Promise that resolves to T; await unwraps it to T
  • Record<K, V> — object type with keys K and values V; equivalent to { [key: K]: V }
  • Partial<T> — all properties of T become optional; useful for patch/update operations

Question 0 of 5

What does Array<T> mean in TypeScript?

function first<T>(arr: Array<T>): T | undefined { return arr[0]; } const n = first([1, 2, 3]); // n: number | undefined const s = first(["a", "b"]); // s: string | undefined