tsconfig.json की Deep Dive
In this page:
{
"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
// 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
// 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
// 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
// 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
// tsconfig.json
// { "extends": "./tsconfig.base.json", "compilerOptions": { "outDir": "dist" } }
console.log("extends reuses a shared base config across multiple projects");
outDirसेट करना लेकिनrootDirनहीं, इसलिए compiled folder structure आपकी expectation से अलग हो सकता है।includeभूल जाना और folder के नीचे हर.tsfile compile हो जाना, tests या scripts सहित।- यह मान लेना कि
excludeएक file को compile होने से रोकता है जब कोई और included file इसे import करती है, क्योंकि imports इसे अब भी pull करते हैं।
Chapter Quiz — Complete all 7 topics to unlock
0/7 topics done
Complete these topics first: