Skillpedia
برمجة عامة75k · #2951

no-unchecked-indexed-access

ما الذي تفعله

تتحقق هذه المهارة من تفعيل خيار الأمان noUncheckedIndexedAccess في TypeScript، وتصلح الشيفرة التي تقرأ عناصر المصفوفة بالفهرس دون فحص. وهي موجهة للمطورين الذين يريدون أخطاء undefined أقل أثناء التشغيل.

متى تستخدمها

  • ✓عندما تطلب من الوكيل فحص إعدادات TypeScript في المشروع بحثًا عن خيارات أمان مفقودة.
  • ✓عندما يتعطل تطبيقك بقيم undefined لم يُحذّر منها TypeScript.
  • ✓عندما تراجع شيفرة معالجة بيانات تقرأ عناصر من المصفوفات حسب موضعها.

رابط المهارة

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

انسخه والصقه في الذكاء الاصطناعي الذي تستخدمه (Claude أو ChatGPT أو Cursor) واطلب منه اتباع التعليمات.

طريقة الاستخدام

أسهل طريقة: انسخ الرسالة والصقها في الذكاء الاصطناعي الذي تستخدمه. سيقرأ المهارة وينفّذ تعليماتها.

رسالة جاهزة للصق

استخدم هذه المهارة لمساعدتي: https://github.com/thedaviddias/Front-End-Checklist/blob/main/skills/no-unchecked-indexed-access/SKILL.md اقرأ ملف SKILL.md في هذا الرابط ونفّذ تعليماته لمهمتي.
تريد أن يجد الذكاء الاصطناعي مهارات مثل هذه بنفسه؟ثبّت خادم Skillpedia MCP المجاني: سطر واحد، ويبحث في 15,000+ مهارة قبل كل مهمة.ثبّته في دقيقة واحدة →

مثال على ما تطلبه من الذكاء الاصطناعي

“يتعطل تطبيقي أحيانًا بأخطاء undefined. هل يمكنك تفعيل إعداد TypeScript الذي يلتقطها وإصلاح الشيفرة التي يُبلغ عنها؟”

5 مهارات جديدة كل أسبوع. قراءة في دقيقة واحدة.

كيف تعمل

يتحقق الوكيل من ملف tsconfig.json ويفعّل الخيار إن كان مفقودًا. ثم يحدّث وصولات المصفوفات التي يُبلغ عنها TypeScript الآن، فيضيف فحوصات أو optional chaining حتى تتعامل الشيفرة مع العناصر المفقودة.

المحتوى التقني (ملف 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 عنصر المصفوفة كأنه موجود دائمًا، حتى عندما تكون المصفوفة فارغة أو يكون الفهرس خارج النطاق.

هل سينتج عن ذلك أخطاء كثيرة جديدة؟

قد يحدث ذلك، وتقول المهارة إن optional chaining وnullish coalescing يعالجان معظمها بوضوح.

ماذا عن 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
آخر تحديث
31‏/10‏/2026

هل هذه المهارة مفيدة؟

0

سجّل الدخول للتصويت.

التعليقات

  • …

المزيد من المهارات من هذا المستودع

مهارات مشابهة