TypeScript · Types that pay for themselves
What does strict mode enable and why does it matter?
Short answer
strict enables a group of checks, including strictNullChecks, noImplicitAny and strictFunctionTypes. It catches a large class of bugs but usually requires real fixes rather than blanket assertions.
The strict flag is a shorthand for several compiler options. The most impactful is strictNullChecks, which stops null and undefined from being silently assignable to every type. noImplicitAny rejects parameters and variables whose type would otherwise be an implicit any. Other flags tighten function assignability and class property initialization.
function greet(name: string | null): string {
if (name === null) {
return "Hello, guest";
}
return "Hello, " + name;
}
const message = greet(null);What strict changes
- strictNullChecks forces null and undefined to be handled explicitly
- noImplicitAny rejects untyped parameters that would become any
- strictFunctionTypes checks function parameter types more carefully
- strictPropertyInitialization requires class fields to be initialized
- useUnknownInCatchVariables types catch bindings as unknown
Turning strict on in an existing codebase often produces a large error list. Enabling the flags individually lets a team make progress without blocking delivery. The important thing is to have a plan to reach the full set rather than leaving the codebase permanently half-strict.
Follow-ups you should expect
Interviewers use these to check whether the first answer was understanding or memorisation.
- 1Which strict flag has the biggest impact?
- 2How would you migrate a large codebase to strict?
- 3What does strictPropertyInitialization require?
- 4Why is useUnknownInCatchVariables safer?
Say it in the interview
strict enables a set of checks, most importantly strictNullChecks and noImplicitAny. It forces me to handle null and undefined explicitly and to type values the compiler cannot infer. The fixes are sometimes noisy, but they usually reveal real edge cases. I prefer enabling strict from the start; when migrating, I enable flags individually and work toward the full set.
Use this as a model, not a script. Saying it in your own words is what makes it survive follow-up pressure.
Related questions
Reading is step one
Now say it out loud.
Understanding an answer and delivering it under pressure are different skills. Rehearse this topic in a live TypeScript mock interview and get scored feedback on depth, clarity and confidence.