본문으로 건너뛰기
Skillpedia
일반 코딩75k · #2951

no-unchecked-indexed-access

하는 일

이 스킬은 TypeScript 안전 옵션인 noUncheckedIndexedAccess가 켜져 있는지 확인하고, 항목을 확인하지 않고 인덱스로 읽는 코드를 고칩니다. undefined 런타임 오류를 줄이려는 개발자를 위한 것입니다.

사용하는 경우

  • ✓프로젝트의 TypeScript 설정에서 빠진 안전 옵션이 있는지 확인해 달라고 요청할 때.
  • ✓TypeScript가 경고하지 않은 undefined 값 때문에 앱이 충돌할 때.
  • ✓위치로 배열 항목을 읽는 데이터 처리 코드를 검토할 때.

스킬 링크

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

복사해서 AI(Claude, ChatGPT, Cursor)에 붙여넣고 지침을 따르도록 요청하세요.

사용 방법

가장 쉬운 방법입니다. 메시지를 복사해 AI에 붙여넣으세요. AI가 스킬을 읽고 지침을 따릅니다.

바로 붙여넣을 수 있는 메시지

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.
AI가 이런 스킬을 알아서 찾아 쓰길 원하시나요?무료 Skillpedia MCP를 설치하세요. 한 줄이면 작업마다 스킬 15,000+개 중에서 검색합니다.1분 만에 설치 →

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는 배열 비었거나 인덱스가 범위를 벗어나도 항목이 항상 있다고 취급합니다.

새로운 오류가 많이 생기나요?

그럴 수 있으며, 스킬은 옵셔널 체이닝과 null 병합 연산자로 대부분 깔끔하게 처리할 수 있다고 설명합니다.

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.

repo: thedaviddias/Front-End-Checklist

인기도

GitHub 스타
75k
순위
#2951
라이선스
MIT
업데이트
2026. 10. 31.

이 스킬이 유용한가요?

0

로그인 투표하려면 로그인하세요.

댓글

  • …

이 저장소의 다른 스킬

비슷한 스킬