TypeScript online compiler

Real TypeScript compiler: type errors, then runs the JavaScript. Runs in your browser.

Learn TypeScript →
main.ts
// Online TypeScript compiler
// Type errors are shown first, then the compiled JavaScript runs.

interface Product {
  name: string;
  price: number;
  tags?: string[];
}

function formatPrice(p: Product): string {
  return `${p.name}: $${p.price.toFixed(2)}`;
}

const items: Product[] = [
  { name: 'Laptop', price: 899 },
  { name: 'Mug', price: 8.99, tags: ['gift'] },
];

items.forEach((p) => console.log(formatPrice(p)));
Output

Press ▶ Run or Ctrl/⌘ + Enter to run your code.