Back
Syntax
Study
Editor
Mode:
HTML
CSS
JavaScript
PHP
Reset
Run »
HTML / CSS / JS
// Install: npm install -g typescript // Compile: tsc hello.ts // Run: node hello.js // Or use ts-node for direct execution: // npm install -g ts-node // ts-node hello.ts // hello.ts const greeting: string = 'Hello, TypeScript!'; const year: number = 2024; const isActive: boolean = true; console.log(`${greeting} (${year})`); // Without TypeScript, this bug only appears at runtime: // Without TS: greet(42) — works, but wrong // With TS: greet(42) — compile error! function greet(name: string): string { return `Hello, ${name}!`; } console.log(greet('Alice')); // console.log(greet(42)); // TypeScript Error: Argument of type 'number' // is not assignable to parameter of type 'string'
Result
Open