TSTypeScript · Lesson 1 of 10

Hello, TypeScript!

TypeScript is a superset of JavaScript. Every .js file is valid TypeScript — you just get to add types on top. Start simple, add types where they help.

TypeScript files end in .ts. The TypeScript compiler (tsc) transpiles them to plain JavaScript. Alternatively, ts-node runs TypeScript directly for scripts and development.

TypeScript
// hello.ts
function greet(name: string): string {
  return `Hello, ${name.toUpperCase()}!`
}

console.log(greet("World"))   // Hello, WORLD!

// TypeScript catches this at compile time — before you run the code:
// greet(42)   // Error: Argument of type 'number' is not assignable to parameter of type 'string'
Bash
# Compile to JS, then run:
tsc hello.ts
node hello.js

# Or run directly with ts-node:
ts-node hello.ts

# Compile entire project with tsconfig:
tsc --init     # generates tsconfig.json
tsc            # compiles everything in project
◆ Note
TypeScript types only exist at compile time. Once compiled to JavaScript, all type information is erased — it adds zero runtime overhead. The types are purely for you, your editor, and the compiler.