"strict": true ਜੋ tsconfig.json ਵਿੱਚ ਹੈ ਇਕੋ ਵਾਰ ਸਖ਼ਤ ਜਾਂਚਾਂ ਦੀ ਇੱਕ ਫੈਮਲੀ ਨੂੰ ਚਾਲੂ ਕਰਦਾ ਹੈ। ਇਹ ਸਾਰੀਆਂ ਨਵੀਆਂ ਪ੍ਰੋਜੈਕਟਾਂ ਲਈ ਨੂੰ ਬਹੁਤ ਜ਼ਿਆਦਾ ਸਿਫਾਰਸ਼ ਕੀਤੀ ਜਾਂਦੀ ਹੈ — ਇਹ ਓਹ ਬੱਗਸ ਨੂੰ ਫੜਦਾ ਹੈ ਜੋ 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 ਨੂੰ ਹੋਰ ਕਿਸਮਾਂ ਤੋਂ ਵੱਖ ਕਰਦਾ ਹੈ, ਇਸ ਲਈ ਕੰਪਾਈਲਰ ਤੁਹਾਨੂੰ "ਮੁਮਕਿਨ ਹੈ ਪਤਾ ਨਾ ਹੋਵੇ" ਨੂੰ ਸਫਲ ਤੁਹਾਡੀ ਨੂੰ ਜ਼ਬਰਦਸਤ ਕਰਦਾ ਹੈ — ਅਤੇ runtime errors ਦੀ #1 ਕਿਸਮ ਨੂੰ ਖਤਮ ਕਰਦਾ ਹੈ ("cannot read property of undefined")।
Flags ਨੂੰ ਵੇਰਵੇ ਤੋਂ ਚਾਲੂ ਕਰੋ (strictNullChecks ਪਹਿਲਾ), ਫੇਰ ਫਾਈਲ ਦੁਆਰਾ ਫਾਈਲ ਨੂੰ ਠੀਕ ਕਰੋ, ਇੱਕ ਵੀ ਵਾਰ ਬਜਾਏ ਇੱਕ ਵਿਸ਼ਾਲ legacy project ਵਿੱਚ ਸਭ ਕੁੱਝ ਨੂੰ ਚਾਲੂ ਕਰਨ ਦਿ।
Cisco strict mode ਤੋਂ ਬਿਨਾ, TypeScript ਅਜੇ ਵੀ ਬਹੁਤ ਤਰਾਂ ਦੀਆਂ ਅਸੁਰੱਖਿਆ ਪੈਟਰਨਾਂ ਦੀ ਆਗਿਆ ਦਿੰਦਾ ਹੈ ਜੋ ਇਹ ਰੋਕਣ ਲਈ ਬਣਾਇਆ ਹੋਇਆ ਸੀ (implicit any, unchecked nulls)।
Strict mode ਉਹ ਜਗ੍ਹਾ ਹੈ ਜਿਥੇ TypeScript ਆਪਣੀ ਸਭ ਮੁੱਲ ਦੀ ਜ਼ਯਾਦਤਰ ਤਸਲੀਮ ਕਰਦਾ ਹੈ — ਇਸ ਨੂੰ ਮਨਜ਼ੂਰ ਸਮਝੋ ਅਤੇ ਸਿਰਫ ਚੰਗੇ ਕਾਰਨਾਂ ਨਾਲ ਵਿਅਕਤੀਗਤ flags ਨੂੰ ਢਿੱਲਾ ਕਰੋ।