tsconfig.json లో "strict": true ఒక సారి కఠినమైన చెక్ల కుటుంబాన్ని చేతిలోకి సక్షమం చేస్తుంది. ఇది అన్ని కొత్త ప్రాజెక్ట్ల కోసం గట్టిగా సిఫార్సు చేయబడింది — TypeScript నిరోధించాలని ఉద్దేశించిన బగ్లను పట్టుకోవడం.
// strictNullChecks — null/undefined are no longer assignable to everything
let name: string = null; // ❌ Error (without strict this compiles, then crashes)
function f(u?: User) { u.name; } // ❌ u is possibly undefined → forces a check
// noImplicitAny — parameters with no inferable type must be annotated
function g(x) {} // ❌ Error: 'x' implicitly has type 'any'
// strictPropertyInitialization — class fields must be initialized
class C { name: string; } // ❌ must init in constructor or mark optional
strictNullChecks గొప్ప: ఇది null/undefined ను ఇతర రకాల నుండి వేరు చేస్తుంది, కనుక కంపైలర్ "లేనివుండవచ్చు" లను ప్రతిచోటా నిర్వహించమని నిర్ణయిస్తుంది — రన్టైమ్ ఎర్రర్ల #1 తరగతిని తొలగిస్తుంది ("cannot read property of undefined").
ఫ్లాగ్లను కొద్దిసారిగా పడుచుకోవండి (strictNullChecks మొదటిగా), ఒక పెద్ద లిగেసీ ప్రాజెక్ట్పై ఎక్కువ నుండి సక్షమం చేయడం కంటే ఫైల్ ద్వారా ఫైల్ ఎర్రర్లను సరిచేయండి.
क严格మోడ్ లేకుండా, TypeScript దీనిని నిరోధించమని ఉద్దేశించిన అనేక సురక్షితం కాని నమూనాలను ఆమోదం చేస్తుంది (implicit any, సరిచేసిన nulls).
Strict mode అనేది TypeScript దాని విలువ యొక్క ఎక్కువ భాగం చేస్తుంది — దీనిని డిఫాల్ట్గా చికిత్స చేయండి మరియు నేర్ కారణ ఉన్నప్పుడు చేసిన కుడ్రుట్ ఫ్లాగ్లను సడిలి వేయండి.