Hello World
TypeScript · Reference cheat sheet
Hello World
TypeScript · Reference cheat sheet
📋 Overview
A TypeScript Hello World is a tiny typed program that compiles to JavaScript and prints a message. It proves tsc (or your runner) is wired correctly.
🔧 Core concepts
| Piece | Role |
|---|---|
.ts file | Source with types |
| Type annotation | Optional : string etc. on bindings |
| Compile | tsc → .js |
| Run | node on the emitted JS (or npx tsx on TS) |
Start simple: one file, one console.log, one annotation.
💡 Examples
Minimal typed hello:
const greeting: string = "Hello, World!";
console.log(greeting);Compile then run:
npx tsc hello.ts --strict
node hello.jsFunction with typed params:
function greet(name: string): string {
return `Hello, ${name}!`;
}
console.log(greet("Ada"));
// greet(42); // Error: Argument of type 'number' is not assignable...Run without a separate emit step (dev convenience):
npx tsx hello.ts⚠️ Pitfalls
- If
tscis “not found,” usenpx tscor install TypeScript locally. - Browser pages need a build step (Vite, etc.) — you cannot drop raw
.tsin<script>without tooling. - Forgetting to recompile after edits means you run stale
.js. anysilences errors — avoid it while learning.