← Back to TypeScript Course | Chapter 26: Monorepos and Large Projects | Lesson 5 of 5

Type Checking की Performance

बड़े TypeScript projects में type checking expensive हो सकती है। अच्छे project boundaries, strict includes, और उपयुक्त compiler settings performance improve कर सकती हैं।

Core Concept

TypeScript का type checker बड़े codebases पर noticeably slow हो सकता है, खासकर deeply nested generics, huge union types, या overly broad include globs के साथ जो उन files को खींच लेते हैं जिन्हें असल में check करने की ज़रूरत नहीं।

उदाहरण: Core Concept

typescript
// Deeply nested generics and huge unions slow down the type checker.
console.log("Large codebases can hit real type-checking performance limits");

Basic Setup

एक basic diagnostic setup tsc --extendedDiagnostics (या --generateTrace) चलाता है यह देखने के लिए कि कौन सी files और language features सबसे ज़्यादा check time consume कर रही हैं, bottleneck guess करने के बजाय।

उदाहरण: Basic Setup

typescript
// tsc --extendedDiagnostics
console.log("extendedDiagnostics shows exactly what's consuming check time");

Typed Example

एक common slowdown का typed example: सैकड़ों string literal members वाला एक union type compiler को हर assignment check पर हर member compare करने के लिए मजबूर करता है, जो एक narrower type या एक enum से measurably slower है।

उदाहरण: Typed Example

typescript
type Status = "a" | "b" | "c"; // a 500-member union would be much slower
function check(s: Status) { return s; }
console.log(check("a"));

Project Usage

एक असली project में, एक monolith को project references (हर एक independently cached) में split करना plus "skipLibCheck": true enable करना आम तौर पर overall check time कम करने के लिए दो सबसे highest-impact changes हैं।

उदाहरण: Project Usage

typescript
// tsconfig.json: { "compilerOptions": { "skipLibCheck": true } }
console.log("skipLibCheck plus project references are the biggest speed wins");

Best Practices

Hot-path type definitions में overly clever recursive conditional types से बचें — वे अन्यथा reasonably-sized codebases पर exponential type-checking time का एक common, hard-to-spot source हैं।

उदाहरण: Best Practices

typescript
// Avoid deeply recursive conditional types in hot-path type definitions.
type Depth1<T> = T extends string ? "string" : "other";
console.log("Recursive conditional types can cause exponential check time");
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. tsc --extendedDiagnostics पहले चलाए बिना slow code guess करना।
  2. Huge unions या deeply nested conditional types लिखना जो checker को slow करते हैं।
  3. एक बड़े project में skipLibCheck को off छोड़ना, इसलिए node_modules में .d.ts files हर बार re-check होती हैं।
चैप्टर सारांश
  • Monorepos एक repository में कई packages रखते हैं, अक्सर एक types package share करते हुए।
  • TypeScript project references और incremental compilation बड़े projects को build करना तेज़ बनाते हैं।
  • Type checking performance project बढ़ने के साथ attention देने लायक है।
🔒

Chapter Quiz — Complete all 5 topics to unlock

0/5 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.