intermediate
Strict mode and inference
Use compiler strictness and local inference to catch unsafe nulls, implicit any, and weak contracts.
Strict TypeScript moves common runtime risks into compile-time feedback: null handling, implicit `any`, unchecked property access, and weak function types. Good code lets inference work locally instead of annotating everything and accidentally widening useful literals.
Annotate public API boundaries and recursive functions where inference fails. Turning strict off to silence errors hides design issues.
const routes = { api: '/v1' } as const; // preserves literal type
On interviews: explain with a concrete example and name what interviewers probe in production code.
Common pitfalls: mixing similar APIs and forgetting edge cases during live coding.
The trade-off is often clarity versus safety or expressiveness versus maintainability. Checklist:
- Keep strict enabled.
- Annotate boundaries, not every local.
- Fix nullability intentionally.