Strictness flags
Turn on strictness for safer code: strict, noImplicitAny, exactOptionalPropertyTypes, noUncheckedIndexedAccess.
Intro
Goal: Enable and understand core strictness flags. These options push errors earlier and improve IDE hints.
- strict
- noImplicitAny
- exactOptionalPropertyTypes
- noUncheckedIndexedAccess
strict + noImplicitAny
strict flips on a bundle of checks; noImplicitAny forbids untyped parameters/vars that default to any.
// tsconfig.json (excerpt)
{
"compilerOptions": {
"strict": true,
"noImplicitAny": true
}
}
// Effect demo
function sum(a, b) { // Error: implicit any
return a + b;
}
function sumOk(a: number, b: number): number {
return a + b;
}All lessons in this course
- Strictness flags
- Target, lib, module, JSX settings
- Project References (intro)