← Back to TypeScript Course | Chapter 17: TypeScript Configuration | Lesson 1 of 7

tsconfig.json की Deep Dive

tsconfig.json file TypeScript को बताती है कि एक project कैसे compile करना है। यह source files, output JavaScript, module system, type checking, और कई दूसरे compiler behaviors control करती है।
Syntax
typescript
{
  "compilerOptions": {
    "target": "ES2020",
    "module": "commonjs",
    "strict": true,
    "outDir": "./dist",
    "rootDir": "./src"
  }
}

Basic tsconfig.json

एक basic tsconfig.json ECMAScript target, module system, source directory, और output directory specify कर सकती है — ये चार settings ही आमतौर पर एक छोटे project को सही से compile करने के लिए काफी हैं।

उदाहरण: Basic tsconfig.json

typescript
// tsconfig.json
// { "compilerOptions": { "target": "ES2020", "module": "commonjs", "rootDir": "src", "outDir": "dist" } }
console.log("target, module, rootDir, outDir are usually enough to start");

include और exclude

include और exclude properties control करती हैं कि TypeScript असल में किन files को project का हिस्सा मानता है, जो compile speed और test fixtures या generated output की accidental type-checking से बचने दोनों के लिए मायने रखता है।

उदाहरण: include and exclude

typescript
// tsconfig.json
// { "include": ["src/**/*"], "exclude": ["node_modules", "**/*.test.ts"] }
console.log("include/exclude control which files TypeScript actually checks");

Compiler Options

compilerOptions वे main settings रखती है जो TypeScript की type checking और JavaScript generation control करती हैं, strictness flags से target syntax तक — यह वह section है जिसे आप एक project की ज़रूरतें बदलने पर सबसे ज़्यादा touch करेंगे।

उदाहरण: Compiler Options

typescript
// tsconfig.json
// { "compilerOptions": { "strict": true, "target": "ES2022" } }
console.log("compilerOptions holds most of the settings you'll actually touch");

Source Maps और Declarations

sourceMap और declaration जैसी options extra output files generate करती हैं जो debugging के लिए उपयोगी हैं (compiled JS को original TS से map करना) और library development के लिए (compiled code के साथ .d.ts files ship करना)।

उदाहरण: Source Maps and Declarations

typescript
// tsconfig.json
// { "compilerOptions": { "sourceMap": true, "declaration": true } }
console.log("sourceMap aids debugging, declaration ships .d.ts files");

Configuration Extend करना

एक config दूसरी configuration file extend कर सकती है ताकि shared compiler settings — जैसे एक company-wide strictness baseline — हर tsconfig.json में duplicate होने के बजाय कई projects में reuse हो सकें।

उदाहरण: Extending Configuration

typescript
// tsconfig.json
// { "extends": "./tsconfig.base.json", "compilerOptions": { "outDir": "dist" } }
console.log("extends reuses a shared base config across multiple projects");
Related Topics
{# common_mistakes/chapter_summary/browser_support: on Hindi pages the view already swaps in the hi_ translation fields (or blanks these out if untranslated), so this renders correctly for both languages without a lang_code check here. #}
आम गलतियां
  1. outDir सेट करना लेकिन rootDir नहीं, इसलिए compiled folder structure आपकी expectation से अलग हो सकता है।
  2. include भूल जाना और folder के नीचे हर .ts file compile हो जाना, tests या scripts सहित।
  3. यह मान लेना कि exclude एक file को compile होने से रोकता है जब कोई और included file इसे import करती है, क्योंकि imports इसे अब भी pull करते हैं।
🔒

Chapter Quiz — Complete all 7 topics to unlock

0/7 topics done

Complete these topics first:

Login to run this code

C/C++/Java/PHP execution requires a free account. Your code is saved — you'll land right back in the editor after logging in.