Enable all strict flags in tsconfig.json (strict: true). Without strict mode, TypeScript allows null access, implicit any, and unchecked function calls that will crash at runtime.
Without strict mode, TypeScript permits operations that are guaranteed to fail at runtime: accessing properties on null, calling functions with wrong argument counts, and treating values as typed when they're actually any. Strict mode catches these at compile time. Enabling it on a mature codebase typically surfaces 50-200 real bugs that were silently waiting to crash in production.
BeforeMerge scans your pull requests against this rule and 3+ others. Get actionable feedback before code ships.
TypeScript's default configuration is intentionally lenient to make adoption easier. But the lenient defaults allow categories of bugs that strict mode catches at compile time:
null and undefined to be assigned to any type. You can call .toString() on a value that is null at runtime and TypeScript won't warn you.any, disabling all type checking.Enabling strict: true is a single flag that turns on all strict checks. It is the difference between TypeScript being a documentation tool and TypeScript being a safety net.
Set "strict": true in your tsconfig.json compilerOptions. This enables: strictNullChecks, noImplicitAny, strictFunctionTypes, strictBindCallApply, strictPropertyInitialization, noImplicitThis, alwaysStrict, and useUnknownInCatchVariables.
// tsconfig.json — NOT strict
{
"compilerOptions": {
"target": "ES2022",
"module": "ESNext",
"strict": false
}
}// These compile without errors — but crash at runtime
function greet(name) {
// name is implicitly any — no type checking
return name.toUpperCase(); // crashes if name is null
}
const user = getUser(); // could return null
console.log(user.email); // null access — no warning// tsconfig.json — strict mode enabled
{
"compilerOptions": {
"target": "ES2022",
"module": "ESNext",
"strict": true
}
}// TypeScript now catches these at compile time
function greet(name: string) {
return name.toUpperCase(); // safe — name is guaranteed to be a string
}
const user = getUser(); // returns User | null
if (user) {
console.log(user.email); // safe — null check narrows the type
}Check your tsconfig.json:
grep -n "strict" tsconfig.jsonIf "strict" is missing or set to false, the project is running without strict mode.
"strict": true in tsconfig.jsonnpx tsc --noEmit to see all new errorsstrictNullChecks, then noImplicitAny// @ts-expect-error sparingly for temporary suppressions with a linked ticket to fix later