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

Declaration Maps की जानकारी

Declaration maps generated .d.ts declaration files को उनके original TypeScript source files से वापस connect करते हैं। ये libraries के लिए विशेष रूप से उपयोगी हैं क्योंकि editors consumed types से implementation source तक navigate कर सकते हैं।
Syntax
typescript
{
  "compilerOptions": {
    "declaration": true,
    "declarationMap": true
  }
}

Declaration Maps क्या करते हैं

जब declarationMap enable होता है, TypeScript specifically इसकी .d.ts declaration files के लिए source maps generate करता है, तो एक editor या debugger एक generated type declaration से सीधे original .ts source पर वापस jump कर सकता है।

उदाहरण: What Declaration Maps Do

typescript
// tsconfig.json
// { "compilerOptions": { "declaration": true, "declarationMap": true } }
console.log("declarationMap lets editors jump from .d.ts back to the original .ts");

Declaration Files

declaration compiler option वे .d.ts files generate करता है जो एक project की public type information describe करती हैं — यही वह है जो दूसरे TypeScript projects को आपके compiled JavaScript को import और type-check करने देता है।

उदाहरण: Declaration Files

typescript
// tsconfig.json
// { "compilerOptions": { "declaration": true } }
console.log("declaration generates the .d.ts files describing public types");

Libraries के लिए Declaration Maps

Library projects को declaration maps से विशेष रूप से फायदा होता है, क्योंकि एक imported type पर "go to definition" उपयोग करने वाले consumers इसके बिना एक readable original source के बजाय एक auto-generated .d.ts file में land होते।

उदाहरण: Declaration Maps for Libraries

typescript
// Without declarationMap, "go to definition" lands in generated .d.ts.
// With it, it lands in the original readable .ts source instead.
console.log("Library consumers benefit most from declaration maps");

Declaration Maps और Composite Projects

Declaration maps composite projects और project references के साथ naturally जुड़ते हैं, जहां generated declarations effectively एक project और इस पर depend करने वाले दूसरे project के बीच public interface boundary की तरह काम करती हैं।

उदाहरण: Declaration Maps and Composite Projects

typescript
// tsconfig.json
// { "compilerOptions": { "composite": true, "declaration": true, "declarationMap": true } }
console.log("Declarations act as the public interface boundary between projects");

Useful Library Configuration

एक well-configured library आमतौर पर declaration output, declaration maps, और regular source maps को साथ combine करती है, consumers को ऐसा code navigate और debug करने में एक smooth experience देते हुए जो उन्होंने नहीं लिखा।

उदाहरण: Useful Library Configuration

typescript
// tsconfig.json
// { "compilerOptions": { "declaration": true, "declarationMap": true, "sourceMap": true } }
console.log("Combining these three gives consumers a smooth debugging experience");
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. declaration: true के बिना declarationMap on करना, इसलिए map करने के लिए कोई .d.ts files exist नहीं करती।
  2. Original .ts sources publish न करना, इसलिए map से "go to definition" के पास खोलने के लिए कुछ नहीं है।
  3. sourceMap (.js के लिए) को declarationMap (.d.ts के लिए) के साथ confuse करना।
चैप्टर सारांश
  • tsconfig.json control करता है कि compiler कैसे behave करता है, और strict mode options stronger checking enable करते हैं।
  • Module resolution और path aliases तय करते हैं कि imports कैसे ढूंढे जाते हैं और import paths कैसे छोटे किए जा सकते हैं।
  • Project references, composite projects, और declaration maps बड़े codebases को organize और build करने में मदद करते हैं।
🔒

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.