← Back to all posts

Getting Started with TypeScript | Note-Tech

TypeScript logo with code editor showing typed interfaces in the background

TypeScript adds a static type layer on top of JavaScript. It catches entire categories of bugs at compile time that would otherwise only surface at runtime—or in production.

Installation

npm install --save-dev typescript
npx tsc --init

Your First Typed Function

function greet(name: string): string {
  return `Hello, ${name}!`;
}

console.log(greet("World")); // Hello, World!
// greet(42); // ❌ compile-time error

Interfaces vs Types

Both define object shapes. Prefer interface when you expect extension; use type for unions and intersections.

interface User {
  id: number;
  name: string;
  email?: string; // optional
}

type Status = "active" | "inactive" | "banned";

Strict Mode

Always start with "strict": true in tsconfig.json. It enables:

  • noImplicitAny — no implicit any types
  • strictNullChecksnull/undefined are not assignable to other types
  • strictFunctionTypes — stricter function parameter checking

Conclusion

TypeScript pays for itself quickly. Enable strict mode, define your data shapes with interfaces, and enjoy IDE autocompletion and compile-time safety across your entire codebase.