"strict": true katika tsconfig.json inabomoa familia ya ukaguzi mkali pokeao. Inapendekezwa kwa juhudi zote mpya — inakamata mabundu ambayo TypeScript ipo ili kuzuia.
{ "compilerOptions": { "strict": true } }
"strict": true katika tsconfig.json inabomoa familia ya ukaguzi mkali pokeao. Inapendekezwa kwa juhudi zote mpya — inakamata mabundu ambayo TypeScript ipo ili kuzuia.
{ "compilerOptions": { "strict": true } }
// 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 ndio kuu: inatengana null/undefined na aina nyingine, kwa hiyo mkusanyaji unakuza kuzingatia "inaweza kuwa haipo" kila mahali — kuondoa tabaka #1 la hitilafu za wakati wa uendeshaji ("cannot read property of undefined").
Bomoa bendera kwa hatua zozote (strictNullChecks kwanza), hitimisha hitilafu faili kwa faili, badala ya kubomolea kila kitu pokeao katika mradi mkubwa wa zamani.
Bila strict mode, TypeScript bado inaruhusu mifumo mingi isiyo salama ambayo inamaanisha kuuzuia (implicit any, null isiyokaguliwa).
Strict mode ndiko TypeScript inatoa thamani yake nyingi — itibue kama chaguo-msingi na tu relax bendera binafsi kwa sababu nzuri.