How to fix 'strictNullChecks' is disabled in TypeScript

TypeScriptINTERMEDIATEMEDIUMUpdated Dec 11, 2025ยท 169 views

The "strictNullChecks is disabled" warning appears when TypeScript detects that strict null checking is turned off in your tsconfig.json. This prevents TypeScript from catching potential null/undefined errors at compile time, which can lead to runtime errors. Enable strictNullChecks to improve type safety.

Quick fix

Fixes 'strictNullChecks' is disabled

{
  "compilerOptions": {
    "strictNullChecks": true
  }
}
  1. Check your tsconfig.json file
  2. Enable strictNullChecks in tsconfig.json
  3. Fix type errors after enabling strictNullChecks
  4. Handle third-party library types
typescript โ€” error
{
"compilerOptions": {
"strictNullChecks": true
}
}
'strictNullChecks' is disabled

What this error means

The "strictNullChecks" compiler option in TypeScript is a critical safety feature that helps catch potential null and undefined errors during compilation. When this option is disabled, TypeScript allows variables to be assigned null or undefined values even when they are declared with non-nullable types. This warning typically appears in IDEs like VS Code or during TypeScript compilation to alert developers that they are missing out on important type safety checks. Without strictNullChecks enabled, TypeScript won't warn you about code like: ```typescript let name: string = null; // No error without strictNullChecks name.toLowerCase(); // Potential runtime error ``` This warning is important because null/undefined errors are among the most common runtime errors in JavaScript applications. By enabling strictNullChecks, you force TypeScript to be more precise about nullability, which helps catch bugs early in the development process.

Typical symptoms

  • TypeScript compiler or IDE shows warning: "strictNullChecks is disabled"
  • No errors when assigning null/undefined to non-nullable types
  • Potential runtime errors from null/undefined values are not caught at compile time
  • Code completion and type checking may be less accurate
  • Third-party libraries with strict null checking may show type errors

Common causes

  1. tsconfig.json has "strictNullChecks": false explicitly set
  2. tsconfig.json inherits from a base config that disables strictNullChecks
  3. Using "strict": false in tsconfig.json (which disables all strict mode options including strictNullChecks)
  4. Project created from a template that disables strict mode by default
  5. Migrating from older TypeScript version where strictNullChecks was not enabled by default

How to fix "'strictNullChecks' is disabled"

1Check your tsconfig.json file

Open your tsconfig.json file and look for the "strictNullChecks" option. It should be set to true for optimal type safety.

json
{
  "compilerOptions": {
    "strictNullChecks": true
  }
}

If you don't see "strictNullChecks" explicitly set, check if "strict" is set to false. The "strict" option enables all strict type-checking options including strictNullChecks.

2Enable strictNullChecks in tsconfig.json

Add or update the "strictNullChecks" option in your tsconfig.json:

json
{
  "compilerOptions": {
    "strictNullChecks": true,
    // other options...
  }
}

Alternatively, you can enable all strict mode options at once:

json
{
  "compilerOptions": {
    "strict": true,
    // other options...
  }
}

The "strict": true option automatically enables strictNullChecks along with other strict type-checking options.

3Fix type errors after enabling strictNullChecks

After enabling strictNullChecks, TypeScript will likely show new errors. Common fixes include:

1. Add explicit null/undefined types:

typescript
// Before: let name: string = getUserName(); // getUserName() might return null
// After:
let name: string | null = getUserName();
if (name) {
  name.toLowerCase();
}

2. Use optional chaining:

typescript
// Before: user.address.city
// After: user?.address?.city

3. Use non-null assertion operator (carefully):

typescript
// Only use when you're certain the value won't be null/undefined
let name: string = getUserName()!;

4. Provide default values:

typescript
let name: string = getUserName() ?? 'default';
4Handle third-party library types

Some third-party libraries may not have perfect type definitions. If you encounter type errors from libraries:

1. Check if types need updating:

bash
npm update @types/package-name

2. Use type assertions when necessary:

typescript
import { SomeType } from 'some-library';

const result = (apiCall() as SomeType) ?? defaultValue;

3. Create custom type declarations:

typescript
// types.d.ts
declare module 'some-library' {
  export interface ImprovedType {
    value: string | null;
  }
}
5Configure IDE to show strictNullChecks warnings

Ensure your IDE (VS Code, WebStorm, etc.) is configured to respect tsconfig.json settings:

1. In VS Code:
- Open Command Palette (Ctrl+Shift+P)
- Type "TypeScript: Select TypeScript Version"
- Choose "Use Workspace Version"
- Restart VS Code if warnings don't appear immediately

2. Check TypeScript version:

bash
npx tsc --version

3. Clear TypeScript cache:

bash
# Delete node_modules/.cache if it exists
rm -rf node_modules/.cache
6Test your application after enabling strictNullChecks

After fixing all type errors, thoroughly test your application:

1. Run your tests:

bash
npm test
# or
yarn test

2. Build your project:

bash
npm run build
# or
yarn build

3. Check for runtime errors:
- Run your application in development mode
- Test common user flows
- Monitor console for any unexpected errors

4. Consider incremental adoption:
If you have a large codebase, you can enable strictNullChecks gradually:

json
{
  "compilerOptions": {
    "strictNullChecks": true,
    "skipLibCheck": true
  }
}

The "skipLibCheck" option can help with third-party library issues while you fix your own code.

Advanced notes

## Understanding strictNullChecks Trade-offs

### Performance Impact
Enabling strictNullChecks has minimal performance impact on compilation. The TypeScript compiler performs additional type checks, but this is negligible for most projects.

### Migration Strategies for Large Codebases

1. Incremental Migration:
- Enable strictNullChecks for new files only using // @ts-strict-null-checks comment
- Gradually fix existing files

2. Partial Strict Mode:

json
{
     "compilerOptions": {
       "strictNullChecks": true,
       "noImplicitAny": false,
       "strictBindCallApply": false
     }
   }

3. Using tsconfig extends:
Create a base config with strictNullChecks enabled and extend it:

json
// tsconfig.base.json
   {
     "compilerOptions": {
       "strictNullChecks": true
     }
   }

   // tsconfig.json
   {
     "extends": "./tsconfig.base.json"
   }

### Common Pitfalls

1. Array methods:

typescript
// Without strictNullChecks: no error
   // With strictNullChecks: error
   const items = [1, 2, 3];
   const found = items.find(x => x > 5); // found is number | undefined
   found.toString(); // Error: Object is possibly 'undefined'

2. Optional parameters vs undefined:

typescript
function greet(name?: string) {
     // name is string | undefined
     return `Hello ${name}`; // Error without null check
   }

3. Index signatures:

typescript
interface Dictionary {
     [key: string]: string;
   }

   const dict: Dictionary = {};
   const value = dict['missing']; // string | undefined

### When to Consider Disabling strictNullChecks

While generally not recommended, there are rare cases where disabling strictNullChecks might be considered:

1. Legacy code migration where fixing all null checks is impractical
2. Prototyping/experimental code where type safety is less critical
3. Build performance for extremely large codebases (though impact is minimal)

If you must disable it temporarily, document why and plan to re-enable it later.

Frequently asked questions

What does "'strictNullChecks' is disabled" mean?
The "strictNullChecks" compiler option in TypeScript is a critical safety feature that helps catch potential null and undefined errors during compilation. When this option is disabled, TypeScript allows variables to be assigned null or undefined values even when they are declared with non-nullable types. This warning typically appears in IDEs like VS Code or during TypeScript compilation to alert developers that they are missing out on important type safety checks.
How do I fix "'strictNullChecks' is disabled"?
The "strictNullChecks is disabled" warning appears when TypeScript detects that strict null checking is turned off in your tsconfig.json. This prevents TypeScript from catching potential null/undefined errors at compile time, which can lead to runtime errors. Enable strictNullChecks to improve type safety.
What causes "'strictNullChecks' is disabled"?
tsconfig.json has "strictNullChecks": false explicitly set tsconfig.json inherits from a base config that disables strictNullChecks Using "strict": false in tsconfig.json (which disables all strict mode options including strictNullChecks)
Is the "'strictNullChecks' is disabled" error serious?
It is a medium-severity error โ€” more of a blocker than a risk. The steps above resolve it.

Official resources & further reading