Skip to content

Conversation

@mtojek
Copy link
Member

@mtojek mtojek commented Dec 23, 2025

Description

This PR enables the noUncheckedIndexedAccess TypeScript compiler option as suggested by @Emyrk.

This option makes array/object indexed access return T | undefined instead of T, improving type safety by ensuring we properly handle cases where indexed access might return undefined.

Progress

Status Count
Original errors 257
Fixed 125
Remaining 132

Error Breakdown (Original 257)

Error Code Count Description
TS2532 86 Object is possibly 'undefined'
TS2345 62 Argument type mismatch with undefined
TS2322 56 Type assignment with undefined
TS18048 46 Variable possibly undefined
Other 7 (TS2538, TS2339, TS2769, TS2488)

Remaining Work

The 132 remaining errors are primarily in:

  • Test files (.jest.tsx, .test.ts)
  • Storybook stories (.stories.tsx)
  • Some production code in pages/

Most fixes involve adding:

  • Non-null assertion (!) where we're certain the value exists
  • Optional chaining (?.) where appropriate
  • Guard clauses for genuine undefined checks

Why This Change?

Before this option, TypeScript would assume indexed access always succeeds:

const item = array[0]; // Type: T (assumed to exist)
item.property; // No error, but could crash at runtime!

After this option:

const item = array[0]; // Type: T | undefined (safer)
item.property; // Error! Must check first
if (item) {
  item.property; // OK
}

⚠️ Draft PR - This is a work in progress. The remaining 132 errors need to be fixed before this can be merged.

This enables the 'noUncheckedIndexedAccess' compiler option which makes
array/object indexed access return 'T | undefined' instead of 'T'.

This change improves type safety by ensuring we properly handle cases
where indexed access might return undefined.

Progress:
- Fixed 125 out of 257 original TypeScript errors
- 132 errors remaining (mostly in test/story files)

The remaining errors are primarily in:
- Test files (.jest.tsx, .test.ts)
- Storybook stories (.stories.tsx)
- Some production code in pages/

Ref: #21381 (comment)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants