Skillpedia
المواقع والواجهات (frontend)75k · #2950

no-explicit-any

ما الذي تفعله

تراجع هذه المهارة ملفات TypeScript بحثًا عن النوع any، الذي يوقف فحص الأنواع. وهي موجهة للمطورين الذين يريدون أن يلتقط TypeScript أخطاء أكثر مبكرًا.

متى تستخدمها

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

رابط المهارة

https://github.com/thedaviddias/Front-End-Checklist/blob/main/skills/no-explicit-any/SKILL.md

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

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

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

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

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

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

“هل يمكنك المرور على ملفات TypeScript لدي واستبدال الأنواع any بأنواع أكثر أمانًا؟”

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

كيف تعمل

يجد الوكيل كل موضع يُستخدم فيه any، بما في ذلك الحالات الضمنية والمؤكدة بالتأكيد (assertion). ويقترح بدائل مثل unknown أو generics أو التحقق، ويبيّن الفحوص اللازمة حيث تُستخدم كل قيمة.

المحتوى التقني (ملف SKILL.md الأصلي)

النص الأصلي من المؤلف، مباشرة من GitHub.

Avoid the any type — use unknown, generics, or type guards instead

The any type is a local opt-out that becomes a global problem: a function returning any propagates unchecked types to every caller, silently undermining the type system across the entire codebase. Replacing any with unknown forces type narrowing at the point of use, turning latent runtime errors into compile-time failures where they are cheapest to fix.

Quick Reference

  • any disables all type checking for a value and cascades to callers
  • unknown is the safe alternative — it requires a type check before use
  • Use generics to express "I accept any type, but it stays consistent"
  • At API boundaries, validate with Zod rather than asserting with as Type

Check

Scan this TypeScript file for uses of the any type (explicit annotations, implicit any from missing types, and type assertions to any). Report each location and suggest a safer alternative.

Fix

Replace the any types in this code with unknown (for values of unknown shape), appropriate generics (for type-consistent operations), or Zod validation (for external data). Show the narrowing or generic constraint needed at each usage site.

Explain

Explain why the any type undermines TypeScript's guarantees, how unknown differs from any, and when a type assertion (as Type) is acceptable versus dangerous.

Code Review

Review all type annotations, function signatures, and external data handling in this file. Flag every explicit or implicit any, any type assertion that lacks a preceding type guard, and any return types inferred as any from untyped dependencies.


For full implementation details, code examples, and framework-specific guidance, see references/rule.md.

Rule page: https://frontendchecklist.io/rules/javascript/no-explicit-any

الأسئلة الشائعة

ما الفرق بين any وunknown؟

يوقف any الفحوص تمامًا، بينما يتطلب unknown التحقق من النوع قبل استخدام القيمة.

هل يجوز أحيانًا استخدام تأكيد النوع؟

تقول المهارة إن التأكيد قد يكون مقبولًا في بعض الحالات، لكنه خطر عندما يُستخدم لإخفاء مشكلات حقيقية.

لماذا نتحقق من البيانات عند حواف التطبيق؟

توصي المهارة بالتحقق من البيانات الخارجية بمكتبة مثل Zod بدلًا من تأكيد نوعها.

التفاصيل

الوصف الأصلي من المؤلف

Use when reviewing TypeScript files for type safety regressions, during code review of functions that handle external data, or when the codebase has ESLint warnings for @typescript-eslint/no-explicit-any.

repo: thedaviddias/Front-End-Checklist

الشعبية

نجوم GitHub
75k
الترتيب
#2950
الترخيص
MIT
آخر تحديث
31‏/10‏/2026

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

0

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

التعليقات

  • …

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

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