no-unchecked-indexed-access
できること
このスキルは、TypeScriptの安全オプションnoUncheckedIndexedAccessが有効か確認し、添字で配列の要素を確認せずに読むコードを修正します。実行時のundefinedエラーを減らしたい開発者向けです。
使う場面
- ✓プロジェクトの設定に安全オプションが不足していないか確認するようエージェントに頼むとき。
- ✓TypeScriptが警告しなかったundefinedの値でアプリが停止するとき。
- ✓配列から位置で要素を読み取るデータ処理のコードを確認しているとき。
スキルのリンク
https://github.com/thedaviddias/Front-End-Checklist/blob/main/skills/no-unchecked-indexed-access/SKILL.mdコピーしてAI(Claude、ChatGPT、Cursor)に貼り付け、指示に従うよう頼んでください。
使い方
いちばん簡単な方法:メッセージをコピーしてAIに貼り付けるだけ。AIがスキルを読んで指示に従います。
貼り付け用メッセージ
Claude Code、Codex、Cursorの場合:プロジェクトのフォルダで実行するとスキルがインストールされます。
SKILL.mdをダウンロードして、エージェントのスキル用フォルダに入れてください。
AIへの頼み方の例
“私のアプリがときどきundefinedのエラーで停止します。これを検出するTypeScriptの設定を有効にして、指摘されたコードを修正してください。”
毎週5つの新しいスキル。1分で読めます。
仕組み
エージェントはtsconfig.jsonを確認し、オプションがなければ有効にします。その後、TypeScriptが指摘する配列へのアクセスを更新し、要素がない場合を扱うよう、チェックやオプショナルチェーンを追加します。
技術的な内容(元のSKILL.md)
作者による元のテキスト(英語)をGitHubからそのまま表示しています。
Enable noUncheckedIndexedAccess to catch out-of-bounds array bugs
TypeScript's default behaviour types array[0] as T, pretending the access is always safe. In reality, the array might be empty or the index might be out of range, leading to silent undefined values that cause downstream crashes. Enabling noUncheckedIndexedAccess surfaces these potential failures as type errors at compile time, requiring developers to prove the access is safe before the code runs.
Quick Reference
- Without the flag, array[0] is typed as T even if the array is empty
- noUncheckedIndexedAccess changes array[n] to return T | undefined
- Forces an explicit check before using any array element accessed by index
- Optional chaining and nullish coalescing handle most false positives cleanly
Check
Check whether noUncheckedIndexedAccess is enabled in the project's tsconfig.json. If not, scan for array index accesses (arr[0], arr[i]) that could fail if the array is shorter than expected.
Fix
Enable noUncheckedIndexedAccess in tsconfig.json, then update any array index accesses that TypeScript now flags to include an explicit undefined check or use optional chaining before the accessed value is used.
Explain
Explain what noUncheckedIndexedAccess does, why the default TypeScript behaviour is unsound for array index access, and how optional chaining and Array.at() interact with the flag.
Code Review
Review all array index accesses in this file (arr[0], arr[i], object[key]). Flag any location where the accessed value is used without a preceding undefined check, even if noUncheckedIndexedAccess is not yet enabled in the project.
For full implementation details, code examples, and framework-specific guidance,
see references/rule.md.
Rule page: https://frontendchecklist.io/rules/javascript/no-unchecked-indexed-access
よくある質問
既定のTypeScriptの動作がここで危険なのはなぜですか?
既定では、配列が空だったり添字が範囲外だったりしても、TypeScriptは配列の要素が常にあるものとして扱います。
多くの新しいエラーが出ますか?
出ることもあり、このスキルは、オプショナルチェーンとnullish合体演算子でほとんどを適切に扱えると説明しています。
Array.at()についてはどうですか?
このスキルは、Array.at()がこのチェックとどう関わるかを説明し、エージェントが適切なパターンを選べるようにしています。
詳細
作者による元の説明
Use when auditing tsconfig.json for missing safety flags, reviewing code that uses array index access in data processing pipelines, or investigating runtime undefined errors that TypeScript did not catch.
人気
- GitHubのスター
- 75k
- ランキング
- #2951
- ライセンス
- MIT
- 更新日
- 2026/10/31
コメント
- …
このリポジトリの他のスキル
frontendchecklist
75kコマンドラインツールを使って、フロントエンドのコードとライブページを、アクセシビリティ、速度、SEO、セキュリティに関する380以上のルールと照らし合わせて確認します。
frontend-checklist-global
75kフロントエンドのプロジェクトを、386のFront-End Checklistのルールすべてと照らし合わせて監査し、見つかった問題ごとに具体的な修正方法を示します。
404-page
75k見つからないページの画面に役立つリンクがあり、本物の404ステータスを返すかを確認し、迷った訪問者が目的のページを見つけられるようにします。
about-page
75kサイトの運営者が誰かを説明する、分かりやすいAboutページがあるかを確認し、訪問者と検索エンジンからの信頼を高めます。
似ているスキル
diffs
394k編集内容の実際の共有可能な差分を、手書きの要約ではなく、ビューアーのリンクや画像ファイルとして作成するようエージェントを支援します。
coding-agent
394kCodex、Claude Code、OpenCodeに大きめのコーディング作業をバックグラウンドのワーカーとして渡し、その進捗を確認するようエージェントを支援します。
gh-issues
394kGitHubのイシューを探し、取り組むものを選び、修正を含むプルリクエストを開くようエージェントを支援します。レビューコメントへの対応も含みます。