Playground
Write or paste any TypeScript and press Run (or ⌘↩). The real TypeScript compiler checks it first, then it runs in your browser, offline too, and prints the way Node does. What you type stays on this device. Every example in the chapters has the same Run and Edit buttons.
// Your playground: write or paste any TypeScript, then press Run (or ⌘↩).
// The real compiler checks the types first, then the code runs in your browser.
type User = { name: string; age?: number };
function greet(user: User): string {
return `Hi ${user.name}${user.age ? `, you're ${user.age}` : ""}`;
}
console.log(greet({ name: "Rohit" }));
console.log(greet({ name: "Ana", age: 30 }));
// greet({ nam: "typo" }); // delete the // at the start to see a type errorBrowser only: Node’s own modules (fs, http, process) aren’t here. An endless loop is stopped after 30 seconds, or press Stop.