|9. tsconfig.json आणि Project Setup
Chapter 9TypeScript~1 min read

tsconfig.json आणि Project Setup

TypeScript Project Configure करणे

tsconfig.json हा TypeScript project चा configuration file आहे. यात compiler options, include/exclude files, strict mode सेट करता येतात.

tsconfig generate करा

bash
# Default tsconfig.json बनवा
tsc --init

Common tsconfig.json settings

json
{
  "compilerOptions": {
    "target": "ES2020",          // output JS version
    "module": "commonjs",        // module system
    "lib": ["ES2020", "DOM"],    // built-in type definitions
    "outDir": "./dist",          // compiled JS output folder
    "rootDir": "./src",          // TypeScript source folder
    "strict": true,              // strict type checking (recommended)
    "noImplicitAny": true,       // any type forbidden
    "strictNullChecks": true,    // null/undefined check
    "esModuleInterop": true,     // CommonJS compatibility
    "skipLibCheck": true,        // skip type-check in node_modules
    "forceConsistentCasingInFileNames": true
  },
  "include": ["src/**/*"],
  "exclude": ["node_modules", "dist"]
}

Node.js + TypeScript Setup

TypeScript Node project setup

bash
npm init -y
npm install typescript ts-node @types/node --save-dev

# tsconfig बनवा
npx tsc --init

# Run TypeScript directly (without compile step)
npx ts-node src/index.ts

# किंवा package.json scripts:
# "scripts": { "dev": "ts-node src/index.ts", "build": "tsc" }
📌

`@types/node`, `@types/react` — या packages मध्ये TypeScript type definitions असतात. Library install केल्यावर त्याचे @types package install करणे लागतं.

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

  • tsconfig.json — TypeScript project config
  • "strict": true — recommend for all projects
  • outDir — compiled JS जिथे जातो
  • @types/package — type definitions
  • ts-node — compile न करता TS run करा
0/9 chapters पूर्ण