Code Reference

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

PieceRole
.ts fileSource with types
Type annotationOptional : string etc. on bindings
Compiletsc.js
Runnode 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.js

Function 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 tsc is “not found,” use npx tsc or install TypeScript locally.
  • Browser pages need a build step (Vite, etc.) — you cannot drop raw .ts in <script> without tooling.
  • Forgetting to recompile after edits means you run stale .js.
  • any silences errors — avoid it while learning.

On this page