← Back to TypeScript Course | Chapter 17: TypeScript Configuration | Lesson 2 of 7

Strict Mode Options

Strict mode enables a group of TypeScript checks designed to catch common programming mistakes. You can enable all strict checks together or control individual checks when necessary.

Enabling strict

The strict option enables a whole collection of stronger type-checking flags at once, which is why most style guides recommend turning it on from the very first commit rather than retrofitting it later.

Example: Enabling strict

typescript
// tsconfig.json
// { "compilerOptions": { "strict": true } }
console.log("strict enables a whole bundle of stronger checks at once");

strictNullChecks

strictNullChecks makes null and undefined distinct types instead of silently assignable to everything, forcing code to explicitly handle the possibility of a missing value before using it — this alone catches a huge class of runtime crashes.

Example: strictNullChecks

typescript
function getLength(s: string | null): number {
  if (s === null) return 0;
  return s.length; // safe: s narrowed to string here
}
console.log(getLength(null));

noImplicitAny

noImplicitAny reports an error anywhere TypeScript would otherwise silently infer the any type for an untyped value, closing one of the most common ways type safety quietly leaks out of a codebase.

Example: noImplicitAny

typescript
function double(x: number): number {
  return x * 2;
}
// Without noImplicitAny, an untyped parameter would silently become 'any'.
console.log(double(5));

strictFunctionTypes and strictBindCallApply

Strict function-type and bind/call/apply checks improve safety when functions are assigned to variables or invoked indirectly, catching parameter-type mismatches that looser settings would let through.

Example: strictFunctionTypes and strictBindCallApply

typescript
function greet(name: string): void {
  console.log("Hello", name);
}
const fn: (name: string) => void = greet;
fn("Ravi");

Choosing Individual Strict Options

Most projects benefit from just turning on strict: true, but individual sub-options can be enabled one at a time when migrating an older, loosely-typed codebase that can't absorb every strict check at once.

Example: Choosing Individual Strict Options

typescript
// tsconfig.json
// { "compilerOptions": { "strictNullChecks": true, "noImplicitAny": false } }
console.log("Individual flags can be enabled incrementally during migration");
🔒

Chapter Quiz — Complete all 7 topics to unlock

0/7 topics done

Complete these topics first:

Login to run this code

C/C++/Java/PHP execution requires a free account. Your code is saved — you'll land right back in the editor after logging in.