AI Hints
Home›TypeScript Tutorial›Configuration and Packages
TypeScript · Lesson 77 of 120

Strict Mode

The safety switches.

⏱ 2 min read▶ Video at 59:58🎓 Free
Watch this lesson in the TypeScript courseWatch on YouTube ↗Full TypeScript course

Strict is a switch for a group of checks. Without it, TypeScript lets many risky things through. Every example in this course has strict on.

Strict Mode
From the video: Strict Mode
  • A group of checks
  • Risky without it
  • Always on here

No implicit any

This function forgot its parameter types. With strict on, TypeScript refuses to guess any. Run it. Both parameters are reported.

app.tstypescript
function addVat(price, rate) {
  return price * (1 + rate);
}
Output
app.ts line 1: Parameter 'price' implicitly has an 'any' type.
app.ts line 1: Parameter 'rate' implicitly has an 'any' type.

What strict turns on

No implicit any requires types where they can't be inferred. Strict null checks makes you handle null and undefined. Strict function types checks callbacks properly. And unknown in catch makes caught errors unknown.

CheckCatches
noImplicitAnymissing types
strictNullChecksnull and undefined
strictFunctionTypeswrong callbacks
useUnknownInCatchVariablesunchecked errors

Summary

Strict turns on the most valuable checks. Keep it on, always. Next, npm packages and their types.

Key takeaways
  • noImplicitAny
  • strictNullChecks
  • Always on
Next up: npm Packages and @types — typed libraries