TypeScriptTypeScript16 min read

Type Inference and Strict Mode

Purpose: understand how TypeScript guesses types and how strict mode protects you. Benefit: less typing, more safety.

David Miller
December 11, 2025
1.7k43

TypeScript often infers types automatically.

Inference

let count = 10;   // inferred as number
let title = "Hi"; // inferred as string

You do not always need to write types.

Strict mode

In tsconfig.json:

{
  "compilerOptions": {
    "strict": true
  }
}

Strict mode:

  • prevents undefined mistakes
  • enforces better typing
  • catches more bugs

Example

let userName: string;
userName = "Tom";
// userName = null; // error in strict mode

Remember

  • inference reduces noise
  • strict mode increases safety
  • both together are powerful
#TypeScript#Beginner#Compiler