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) واطلب منه اتباع التعليمات.
طريقة الاستخدام
أسهل طريقة: انسخ الرسالة والصقها في الذكاء الاصطناعي الذي تستخدمه. سيقرأ المهارة وينفّذ تعليماتها.
رسالة جاهزة للصق
لـ Claude Code أو Codex أو Cursor: شغّله داخل مجلد مشروعك وستُثبَّت المهارة.
نزّل ملف SKILL.md وضعه في مجلد مهارات وكيلك.
مثال على ما تطلبه من الذكاء الاصطناعي
“يتعطل تطبيقي أحيانًا بأخطاء 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.
الشعبية
- نجوم GitHub
- 75k
- الترتيب
- #2951
- الترخيص
- MIT
- آخر تحديث
- 31/10/2026
التعليقات
- …
المزيد من المهارات من هذا المستودع
frontendchecklist
75kيفحص شيفرة الواجهة الأمامية والصفحات الحية مقابل أكثر من 380 قاعدة للوصول وسرعة الأداء وتحسين محركات البحث والأمان، بأداة سطر أوامر.
frontend-checklist-global
75kيدقق مشروع الواجهة الأمامية وفق كل قواعد Front-End Checklist البالغ عددها 386، ويقدم إصلاحًا محددًا لكل مشكلة وجدت.
404-page
75kيتأكد من أن صفحة الصفحات غير الموجودة تقدم روابط مفيدة وتُرجع رمز حالة 404 حقيقيًا، لمساعدة الزوار التائهين على إيجاد طريقهم.
about-page
75kيراجع ما إذا كان لموقعك صفحة «من نحن» واضحة تشرح من يديره، لبناء الثقة لدى الزوار ومحركات البحث.
مهارات مشابهة
diffs
394kيتيح لوكيلك إنتاج فرق تعديلات حقيقي يمكن مشاركته، كرابط عرض أو ملف صورة، بدلاً من ملخص مكتوب يدوياً.
coding-agent
394kيساعد وكيلك على تسليم مهمة برمجة كبيرة إلى Codex أو Claude Code أو OpenCode كعامل في الخلفية، ثم متابعة تقدمها.
gh-issues
394kيساعد وكيلك على إيجاد مشكلات GitHub واختيار ما ستعمل عليه، وفتح طلبات سحب بالإصلاحات، ومتابعة تعليقات المراجعة.