← Back to Tutorial
TypeScript Compiler
TypeScript Code
Clear
Compile ▶
function calculateTax<T extends { price: number }>(items: T[]): number { return items.reduce((sum, item) => sum + item.price * 0.08, 0); } const electronics = [{ price: 99.99 }, { price: 299.99 }]; const books = [{ price: 19.99 }, { price: 39.99 }]; console.log(calculateTax(electronics)); console.log(calculateTax(books));
Output
Download JS
TypeScript code will be compiled here