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 wherearr[5]orrecord[key]is typed as always present;.at(),Map.get()andfor...ofare already honest; neither flag is part ofstrictexactOptionalPropertyTypes(TS 4.4):prop?: Tmeans "may be missing", not "may beundefined", so{ prop: undefined }is rejected (TS2375 / TS2412); it matters because spreads,inandObject.keystreat a presentundefineddifferently 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 inreturnconditionals; andnoUncheckedSideEffectImports(5.6, on by default in 6.0) - Version context: TypeScript 5.9
tsc --initturns both flags on, and TypeScript 6.0 makesstrictthe default - Rollout: enable per package, fix with narrowing patterns (check then use a local,
Map, omit keys instead of writingundefined), 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.