TypeScript 7 · Types

Write a generic function

Keep the relationship between input and output types.

function first<T>(items: T[]): T | undefined {
  return items[0];
}

Official TypeScript 7 documentation

More types commands

All types commands · TypeScript 7 cheatsheet

Was this page helpful?