← Back to Tutorial
TypeScript Compiler
TypeScript Code
Clear
Compile ▶
// TypeScript generics example function first<T>(array: T[]): T { return array[0]; } function last<T>(array: T[]): T { return array[array.length - 1]; } const userIds = ["user1", "user2", "user3"]; const scores = [95, 87, 92]; console.log(first(userIds)); console.log(last(scores));
Output
Download JS
TypeScript code will be compiled here