← Back to TypeScript Course | Chapter 27: Migration from JavaScript | Lesson 5 of 6

धीरे-धीरे Migration

Gradual migration एक project को manageable stages में convert करता है। JavaScript और TypeScript साथ exist कर सकते हैं जबकि codebase stronger typing की ओर बढ़ता है।
Syntax
typescript
// tsconfig.json (loose at first, tighten later)
{
  "compilerOptions": {
    "allowJs": true,
    "checkJs": false,
    "strict": false
  }
}

Core Concept

Gradual migration एक JavaScript codebase को हफ्तों या महीनों में, file by file, TypeScript में move करने की practice है, एक बड़े rewrite पर दूसरे सभी काम को block करने के बजाय — दोनों file types पूरे समय साथ compile होते हैं।

उदाहरण: Core Concept

typescript
// utils.ts and legacy.js compile together throughout the migration.
console.log("Gradual migration moves files to TypeScript over time, not all at once");

Basic Setup

एक basic setup allowJs, initially checkJs: false, और एक loose (non-strict) tsconfig.json combine करता है, इसलिए project transition के दौरान build होता रहता है, पहली .ts file आते ही टूटने के बजाय।

उदाहरण: Basic Setup

typescript
// tsconfig.json: { "allowJs": true, "checkJs": false, "strict": false }
console.log("A loose config keeps the project building during the transition");

Typed Example

Usual sequencing का एक typed example: सबसे कम internal dependencies वाली files पहले convert करें (utility/helper modules), क्योंकि उन्हें passing type checks पाने के लिए सबसे कम दूसरे code को touch करने की ज़रूरत होती है।

उदाहरण: Typed Example

typescript
// Convert low-dependency utility files first:
function formatCurrency(amount: number): string {
  return `$${amount.toFixed(2)}`;
}
console.log(formatCurrency(19.5));

Project Usage

एक असली project में, teams अक्सर mandate करती हैं कि कोई भी *new* file पहले दिन से TypeScript में लिखी जाए, जबकि existing .js files को opportunistically convert किया जाता है जब भी वे किसी unrelated change के लिए touch हों।

उदाहरण: Project Usage

typescript
// Policy: all NEW files must be .ts; existing .js files convert opportunistically.
console.log("New-file TypeScript mandate plus opportunistic old-file conversion");

Best Practices

Migrated-vs-remaining file counts को visibly track करें (एक CI check या dashboard) इसलिए migration चुपचाप stall नहीं होता एक बार easy, low-dependency files हो जाएं और सिर्फ hard, tangled वाली बचें।

उदाहरण: Best Practices

typescript
// CI check: migratedFiles / totalFiles as a visible percentage.
console.log("Track migration progress so it doesn't quietly stall");
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. हर file को एक साथ .ts में rename करना, छोटे steps में migrate करने के बजाय।
  2. strict को हमेशा के लिए off छोड़ना, इसलिए project को पूरा benefit कभी नहीं मिलता।
  3. सबसे complex files से शुरू करना, कोई dependencies न रखने वाले छोटे leaf modules के बजाय।
🔒

Chapter Quiz — Complete all 6 topics to unlock

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