Skip to content
Skillpedia
General coding75k · #2951

no-unchecked-indexed-access

What it does

This skill checks whether the TypeScript safety option noUncheckedIndexedAccess is on, and fixes code that reads array items by index without checking them. It is for developers who want fewer runtime undefined errors.

When to use it

  • ✓When you ask the agent to check the TypeScript settings of a project for missing safety options.
  • ✓When your app crashes with undefined values that TypeScript did not warn about.
  • ✓When you are reviewing data processing code that reads items from arrays by position.

Skill link

https://github.com/thedaviddias/Front-End-Checklist/blob/main/skills/no-unchecked-indexed-access/SKILL.md

Copy it and paste it into your AI (Claude, ChatGPT or Cursor), asking it to follow the instructions.

How to use

The easiest way: copy the message and paste it into your AI. It reads the skill and follows the instructions.

Ready-to-paste message

Use this skill to help me: https://github.com/thedaviddias/Front-End-Checklist/blob/main/skills/no-unchecked-indexed-access/SKILL.md Read the SKILL.md file at that link and follow its instructions for my task.
Want your AI to find skills like this on its own?Install the free Skillpedia MCP: one line, and it searches 15,000+ skills before each task.Install in 1 minute →

Example of what to ask your AI

“My app sometimes crashes with undefined errors. Can you turn on the TypeScript setting that catches these and fix the code it flags?”

5 new skills a week. 1 minute to read.

How it works

The agent checks the tsconfig.json file and turns on the option if it is missing. It then updates the array accesses that TypeScript now flags, adding checks or optional chaining so the code handles missing items.

Technical content (original SKILL.md)

Original text by the author, straight from 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

FAQ

Why is the default TypeScript behavior risky here?

By default TypeScript treats an array item as always present, even when the array is empty or the index is out of range.

Will this create a lot of new errors?

It can, and the skill says optional chaining and nullish coalescing handle most of these cleanly.

What about Array.at()?

The skill explains how Array.at() interacts with this check, so the agent can pick the right pattern.

Details

Original description by the author

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.

repo: thedaviddias/Front-End-Checklist

Popularity

GitHub stars
75k
Ranking position
#2951
License
MIT
Updated
10/31/2026

Is this skill useful?

0

Sign in to vote.

Comments

  • …

More skills from this repository

Similar skills