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

type-only-imports

ما الذي تفعله

تفحص هذه المهارة عبارات الاستيراد في TypeScript وتعلّم الاستيرادات الخاصة بالأنواع فقط. وهي موجهة إلى المطورين الذين يريدون حزمًا أصغر ومشكلات تبعية أقل.

متى تستخدمها

  • ✓عندما يستورد ملف TypeScript وحدات تُستخدم للأنواع فقط.
  • ✓عندما تتضمن الحزمة وحدات يبدو أنها تُحمَّل للأنواع فقط.
  • ✓عندما يُعدّ مشروع TypeScript جديد بقواعد استيراد نظيفة.

رابط المهارة

https://github.com/thedaviddias/Front-End-Checklist/blob/main/skills/type-only-imports/SKILL.md

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

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

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

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

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

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

“نظام البناء عندي في TypeScript يسحب وحدة كبيرة أستخدمها للأنواع فقط. هل يمكنك إصلاح الاستيرادات؟”

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

كيف تعمل

يجد الوكيل الاستيرادات المستخدمة للأنواع فقط ويغيّرها إلى import type. ثم يزيلها المترجم عند بناء الكود.

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

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

Use import type for type-only imports

Regular imports cause the JavaScript runtime to evaluate and execute the imported module even when only a TypeScript type from that module is used. This can increase bundle size, introduce unintended side effects, and create circular dependency issues that are otherwise avoidable. Using import type makes the erased-at-runtime nature of type imports explicit and enables bundlers and the TypeScript compiler to handle them optimally.

Quick Reference

  • import type is erased entirely at compile time — no runtime module evaluation
  • Prevents accidentally importing a value when only a type is needed
  • Reduces circular dependency issues caused by type-only relationships
  • verbatimModuleSyntax in TypeScript 5 enforces this automatically

Check

Review the import statements in this TypeScript file and identify any imports where only types or interfaces are used. These should use import type instead of a regular import.

Fix

Convert the identified regular imports to import type where the imported binding is only used as a TypeScript type annotation and not as a runtime value.

Explain

Explain the difference between import and import type in TypeScript, why type-only imports should be declared explicitly, and how verbatimModuleSyntax enforces this at the compiler level.

Code Review

Inspect all import statements in this file. For each import, check whether the imported name appears only in type positions (annotations, generics, implements clauses) versus runtime positions (function calls, new, typeof). Flag any regular import that is used only as a type.


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

Rule page: https://frontendchecklist.io/rules/javascript/type-only-imports

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

ماذا يفعل import type؟

يخبر المترجم أن الاستيراد يُحذف وقت البناء، فلا تُحمَّل أي وحدة وقت التشغيل.

ما هو verbatimModuleSyntax؟

هو إعداد في TypeScript 5 يفرض هذه القاعدة تلقائيًا، بحسب المهارة.

هل يساعد هذا في تقليل الاعتماد الدائري؟

تقول المهارة إن الاعتماد الدائري الذي يمكن تجنبه يمكن تقليله باستخدام الاستيرادات الخاصة بالأنواع فقط.

التفاصيل

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

Use when auditing import statements in TypeScript files, setting up a new TypeScript project, or investigating unexpected bundle inclusions from type-only dependencies.

repo: thedaviddias/Front-End-Checklist

الشعبية

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

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

0

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

التعليقات

  • …

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

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