Skip to content
beginner

Generic Function Basics

Create a generic function that works with any type.

function identity___(value: ___): ___ {
  return value;
}

const num = identity(42);        // type: number
const str = identity("hello");   // type: string
const arr = identity([1, 2, 3]); // type: number[]
0/3 filled tab moves · Ctrl+↵ submits · Ctrl+Shift+↵ runsstarter code