Skip to the solution
MediumFrontend12 min read

How do noUncheckedIndexedAccess, exactOptionalPropertyTypes and TS 5.6+ checks harden 2025 codebases?

482 views

The problem

Question presented to candidate: "strict is already on in our codebase. Someone proposes adding noUncheckedIndexedAccess and exactOptionalPropertyTypes, and upgrading TypeScript for the newer 5.6+ checks. What does each one catch that strict does not, and how would you roll them out?"

What a strong answer should cover:

  • noUncheckedIndexedAccess (TS 4.1): index-signature and array element reads get | undefined, closing the hole where arr[5] or record[key] is typed as always present; .at(), Map.get() and for...of are already honest; neither flag is part of strict
  • exactOptionalPropertyTypes (TS 4.4): prop?: T means "may be missing", not "may be undefined", so { prop: undefined } is rejected (TS2375 / TS2412); it matters because spreads, in and Object.keys treat a present undefined differently from a missing key
  • TS 5.6+ checks that need no flag or come with strict: always-truthy / never-nullish conditions (TS2872, TS2869), strictBuiltinIteratorReturn, plus 5.7 never-initialized variables and 5.8 per-branch checks in return conditionals; and noUncheckedSideEffectImports (5.6, on by default in 6.0)
  • Version context: TypeScript 5.9 tsc --init turns both flags on, and TypeScript 6.0 makes strict the default
  • Rollout: enable per package, fix with narrowing patterns (check then use a local, Map, omit keys instead of writing undefined), avoid ! as a blanket fix

Clarifying questions expected:

  • Which TypeScript version is the codebase on, and can it upgrade?
  • How large is the codebase, and is there a monorepo where flags can be enabled package by package?

Code / implementation expected: Optional β€” an index read that crashes under strict alone, and a spread that overwrites a default with undefined.

  • strict
  • noUncheckedIndexedAccess

Try it yourself

Sketch your approach before you read the solution. That is what the interview tests.

Stuck? Get a hint.

A short nudge toward the approach. It will not give the answer away.

Solution

The solution is hidden so you can try first

12 min read Β· 10 sections

Run the code

Edit the code and run it here. Each console line with an expected value becomes a test.

TypeScriptThe index-access hole that strict leaves open
TypeScriptMissing vs undefined: what exactOptionalPropertyTypes protects
TypeScriptBugs TypeScript 5.4 accepts and 5.6 rejects

Discussion

Other approaches, follow-ups and how it went in real interviews.

Sign in to join the discussion.

No comments yet. Share how you would answer it.

Question 45 of 81 in TypeScript

Keep your momentum going.

Mark this question solved to track your progress, then take the next one while it is fresh.

Up nextMedium

What are `const` type parameters (`<const T>`) and why are they better than `as const`?

Continue