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

Project References की जानकारी

Project references एक बड़े TypeScript codebase को छोटे TypeScript projects में divide करने देते हैं। हर referenced project का अपना tsconfig.json और build output हो सकता है, organization और incremental builds improve करते हुए।
Syntax
typescript
{
  "references": [{ "path": "../other-project" }]
}

Basic Project Reference

references property एक TypeScript project की config से दूसरे project की config की ओर point करती है, एक बड़े codebase को छोटे, independently-buildable pieces में split होने देते हुए जो अब भी एक-दूसरे के against type-check करते हैं।

उदाहरण: Basic Project Reference

typescript
// app/tsconfig.json
// { "references": [{ "path": "../shared" }] }
console.log("references points from one project's config to another's");

Referenced Project Configuration

एक referenced project को एक compatible configuration चाहिए, सबसे ज़्यादा ज़रूरी composite: true, ताकि TypeScript compiler उस declaration output generate कर सके जिसपर इसे reference करने वाले दूसरे projects depend करेंगे।

उदाहरण: Referenced Project Configuration

typescript
// shared/tsconfig.json
// { "compilerOptions": { "composite": true, "declaration": true } }
console.log("composite: true lets other projects depend on this one's output");

Application और Library Projects

एक common structure reusable library code को उसे consume करने वाली application से अपने ही referenced project में अलग करता है, ताकि library को कुछ हद तक independently build, test, और version किया जा सके।

उदाहरण: Application and Library Projects

typescript
// packages/lib/tsconfig.json    (composite: true)
// packages/app/tsconfig.json    references: [{ path: "../lib" }]
console.log("Library and app split into separately buildable projects");

Referenced Projects Build करना

TypeScript का build mode (tsc -b) project references समझता है और referenced projects को सही dependency order में अपने आप build करता है, जो projects last build के बाद से नहीं बदले उन्हें skip करते हुए।

उदाहरण: Building Referenced Projects

typescript
// tsc -b
console.log("tsc -b builds referenced projects in correct dependency order");

Project References के फायदे

Project references बड़े codebases पर concerns separate करके, unnecessary recompilation कम करके, और packages के बीच dependency graph को shared node_modules के through implicit के बजाय explicit बनाकर फायदा देती हैं।

उदाहरण: Benefits of Project References

typescript
// Faster incremental builds, clear dependency graph, separated concerns.
console.log("Project references scale TypeScript to large, multi-package codebases");
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. एक project reference करना जो composite नहीं है, जो एक error है।
  2. Plain tsc चलाना बजाय tsc -b के, इसलिए referenced projects पहले build नहीं होते।
  3. path को किसी source file की ओर point करना बजाय referenced project के folder या tsconfig.json के।
🔒

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.