Back to Blog
TypeScriptStrict ModeType SafetyConfiguration

TypeScript Strict Mode Explained

Enable and understand TypeScript strict mode. From compiler flags to common errors to migration strategies.

B
Bootspring Team
Engineering
May 28, 2021
6 min read

Strict mode catches more bugs at compile time. Here's how to use it effectively.

Enabling Strict Mode

Loading code block...

strictNullChecks

Loading code block...

noImplicitAny

Loading code block...

strictFunctionTypes

Loading code block...

strictBindCallApply

Loading code block...

strictPropertyInitialization

Loading code block...

noImplicitThis

Loading code block...

useUnknownInCatchVariables

Loading code block...

Migrating to Strict Mode

Loading code block...
Loading code block...

Best Practices

Migration: ✓ Enable flags incrementally ✓ Fix one file at a time ✓ Use // @ts-expect-error for known issues ✓ Add tests before migrating Patterns: ✓ Use type guards for narrowing ✓ Prefer unknown over any ✓ Initialize class properties ✓ Handle null/undefined explicitly Avoid: ✗ Using ! assertion excessively ✗ Casting to any to silence errors ✗ Disabling rules per-file ✗ Ignoring compiler warnings

Conclusion

Strict mode catches bugs that would otherwise appear at runtime. Enable it for new projects and migrate existing ones gradually. The initial investment in fixing errors pays off with more reliable code and better developer experience through improved editor support.

Share this article

Help spread the word about Bootspring

Related articles