|1. TypeScript म्हणजे काय?
Chapter 1TypeScript~1 min read

TypeScript म्हणजे काय?

JavaScript + Types

TypeScript हे JavaScript चं superset आहे — म्हणजे सगळं JavaScript valid TypeScript आहे, पण TypeScript मध्ये extra features आहेत. सर्वात महत्त्वाचं feature म्हणजे Static Typing — variables आणि functions चे types define करता येतात.

Marathi Analogy

JavaScript म्हणजे बिना helmet चं bike चालवणं — fast आहे पण risky. TypeScript म्हणजे helmet + safety gear — थोडा वेळ जास्त लागतो पण bugs खूप कमी होतात!

TypeScript का वापरायचं?

  • Bugs compile time मध्येच पकडता येतात, runtime मध्ये नाही
  • VS Code मध्ये auto-complete (IntelliSense) खूप powerful होतो
  • Large codebases manage करणे सोपं होतं
  • Team मध्ये code समजायला सोपं — types documentation सारखं काम करतात
  • React, Angular, Node.js सगळे TypeScript support करतात

JavaScript vs TypeScript comparison

typescript
// JavaScript — कोणताही type चालतो
function add(a, b) {
  return a + b;
}
add(5, "10"); // "510" — silent bug!

// TypeScript — types define केले
function add(a: number, b: number): number {
  return a + b;
}
add(5, "10"); // ❌ ERROR at compile time: Argument of type 'string' is not assignable to parameter of type 'number'

TypeScript Install आणि Compile

Setup

bash
# TypeScript globally install करा
npm install -g typescript

# Version check
tsc --version

# TypeScript file compile करा
tsc hello.ts        # hello.js बनतो

# Watch mode
tsc hello.ts --watch

Key Points — लक्षात ठेवा

  • TypeScript = JavaScript + Static Types
  • Browser TypeScript directly run करत नाही — compile करावं लागतं
  • tsc — TypeScript compiler
  • .ts extension — TypeScript files
  • Compile errors = bugs caught before running
0/9 chapters पूर्ण