Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

chore(site): enable noUncheckedIndexedAccess TypeScript option#21383

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Draft
mtojek wants to merge1 commit intomain
base:main
Choose a base branch
Loading
fromenable-no-unchecked-indexed-access

Conversation

@mtojek
Copy link
Member

Description

This PR enables thenoUncheckedIndexedAccess TypeScript compiler option assuggested by @Emyrk.

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

Progress

StatusCount
Original errors257
Fixed125
Remaining132

Error Breakdown (Original 257)

Error CodeCountDescription
TS253286Object is possibly 'undefined'
TS234562Argument type mismatch with undefined
TS232256Type assignment with undefined
TS1804846Variable possibly undefined
Other7(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 inpages/

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:

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

After this option:

constitem=array[0];// Type: T | undefined (safer)item.property;// Error! Must check firstif(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 makesarray/object indexed access return 'T | undefined' instead of 'T'.This change improves type safety by ensuring we properly handle caseswhere 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 freeto join this conversation on GitHub. Already have an account?Sign in to comment

Reviewers

No reviews

Assignees

@mtojekmtojek

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

2 participants

@mtojek

[8]ページ先頭

©2009-2025 Movatter.jp