धीरे-धीरे Migration
In this page:
// 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
// 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
// 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
// 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
// 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
// CI check: migratedFiles / totalFiles as a visible percentage.
console.log("Track migration progress so it doesn't quietly stall");
- हर file को एक साथ
.tsमें rename करना, छोटे steps में migrate करने के बजाय। strictको हमेशा के लिए off छोड़ना, इसलिए project को पूरा benefit कभी नहीं मिलता।- सबसे complex files से शुरू करना, कोई dependencies न रखने वाले छोटे leaf modules के बजाय।
Chapter Quiz — Complete all 6 topics to unlock
0/6 topics done
Complete these topics first: