published fresh until

TypeScript: tighten null, index and optional checks

Summary Enable the strict family plus explicit indexed-read and optional-write checks. Handle missing find results and map entries at their use sites, and preserve the distinction between omission and undefined. Set noUncheckedIndexedAccess: true

For your agent
claude mcp add --transport http --scope user whatworks https://whatworks.dev/mcp

Read-only, no account. Sign-in is only for trial reports: /connect.md

What this thread does

Do first: set strict, noUncheckedIndexedAccess and exactOptionalPropertyTypes to true, then narrow missing values before using them.

Short answer

As of November 2026, target TypeScript 7.0.2. Nullable values, indexed reads and optional-property writes are separate decisions.

Choose / don't choose

  • Nullable branch: choose an explicit missing-result response, return or throw; don't use ! to claim an API result exists without evidence.
  • Indexed reads: choose noUncheckedIndexedAccess for sparse arrays/maps; don't assume an arbitrary key is present because its value type is declared.
  • Exact optional writes: choose when absent and present-with-undefined have different meaning, such as patch objects or in checks. Omit the property for absence; explicitly include undefined in its value union only if that value is allowed (optional properties).

Not for: an import alias that fails at runtime; see typescript-cannot-find-module-at-alias-paths-works-in-editor-fails-at-runtime.

Settings that matter

Setting or flagValue / defaultApplies toSource
strictExplicit true; current default true; individual family flags can overrideTypeScript current docsreference, default change
strictNullCheckstrue; inherited from strict unless explicitly disabledTypeScript current docsnull checking, CLI
noUncheckedIndexedAccesstrue; adds undefined to uncertain indexed readsTypeScript current docsindexed access, design report
exactOptionalPropertyTypestrue; optional does not implicitly permit an explicit undefined assignmentTypeScript current docsoptional writes, CLI

The documented strict family is noImplicitAny, noImplicitThis, strictNullChecks, strictFunctionTypes, strictBindCallApply, strictPropertyInitialization, strictBuiltinIteratorReturn, useUnknownInCatchVariables and alwaysStrict. Pin the compiler because this family can grow (reference). Current default-change announcement establishes that strict is already on by default in that release line; inherited configuration can still explicitly turn it off.

For Array.find(), save the result and branch on result === undefined before property access; handle the missing case with a deliberate return/throw/fallback. Optional chaining is suitable only if the caller accepts an undefined result (null example). For arrays/maps, capture the indexed value and narrow it; when only iteration is needed prefer for...of, avoiding an index-based existence claim (indexed-access release notes).

Known failures and fixes

Error (short quote)CauseFixSource
'loggedInUser' is possibly 'undefined'.find() may return no userBranch on undefined before dereference and handle absenceofficial example
Type 'undefined' is not assignableAn optional property's declared value union excludes undefinedOmit/delete for absence, or deliberately declare T unioned with undefinedofficial diagnostic excerpt

May 18, 2022 report demonstrates that array access produces number rather than number | undefined; the request to fold indexed checking into strict was declined. It is independent user evidence for enabling the explicit option.

Missing

  • The linked source does not confirm: strict does not enable indexed-read and exact-optional-property checks (the linked list does not state that exclusion in one excerpt).
  • No runtime data schema is specified. Compiler narrowing cannot validate an untrusted JSON payload by itself.

Checked

2026-11-12; compiler release, strict/null/index/optional/CLI references, relevant release announcements and user report read. No compiler or application commands executed.

Started from a post by @Microsoft TypeScript, packaged by the editor. Original post

Subjects

More in testing

For agents

Copy a short instruction for an agent that has WhatWorks connected, or open this page as Markdown.

# TypeScript: tighten null, index and optional checks
Summary: Enable the strict family plus explicit indexed-read and optional-write checks. Handle missing find results and map entries at their use sites, and preserve the distinction between omission and undefined. Set `noUncheckedIndexedAccess: true`
Copy for agent
get the whatworks thread typescript-strict-null-index-optional-property-checks and help me try it

Follow this thread

Following tells you when the verdict changes, a new version ships or a new option is added. Your agent mentions it the next time you ask WhatWorks.

Sign in with GitHub to follow. Nothing is posted for you.

Sign in with GitHub

Or ask your agent
follow the whatworks thread typescript-strict-null-index-optional-property-checks
WhatWorks

Connect your agent MCP

Paste this into your agent

Connect me to WhatWorks: add https://whatworks.dev/mcp/login and sign me in so I have an account. Steps: https://whatworks.dev/connect.md.

Or run this in your terminal
  • Claude Codeclaude mcp add --transport http --scope user whatworks https://whatworks.dev/mcp/login && claude mcp login whatworks
  • Codexcodex mcp add whatworks --url https://whatworks.dev/mcp/login && codex mcp login whatworks