Langsung ke konten
Skillpedia
Pemrograman umum75k · #3067

type-only-imports

Fungsinya

Skill ini memeriksa pernyataan impor TypeScript dan menandai impor khusus tipe dengan benar. Skill ini cocok untuk developer yang menginginkan bundle lebih kecil dan lebih sedikit masalah dependensi.

Kapan dipakai

  • ✓Saat file TypeScript mengimpor modul yang hanya dipakai sebagai tipe.
  • ✓Saat bundle menyertakan modul yang tampaknya hanya ditarik untuk tipe.
  • ✓Saat menyiapkan proyek TypeScript baru dengan aturan impor yang rapi.

Link skill

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

Salin lalu tempelkan ke AI Anda (Claude, ChatGPT, atau Cursor) dan minta AI mengikuti instruksinya.

Cara pakai

Cara paling mudah: salin pesan ini dan tempelkan ke AI Anda. AI akan membaca skill dan mengikuti instruksinya.

Pesan siap tempel

Gunakan skill ini untuk membantu saya: https://github.com/thedaviddias/Front-End-Checklist/blob/main/skills/type-only-imports/SKILL.md Baca file SKILL.md di link tersebut dan ikuti instruksinya untuk tugas saya.
Mau AI Anda menemukan skill seperti ini sendiri?Pasang MCP Skillpedia gratis: cukup satu baris, dan AI mencari di antara 15.000+ skill sebelum tiap tugas.Pasang dalam 1 menit →

Contoh permintaan ke AI

“Build TypeScript saya menarik modul besar yang hanya saya pakai untuk tipe. Bisakah Anda memperbaiki impornya?”

5 skill baru setiap minggu. 1 menit baca.

Cara kerjanya

Agent menemukan impor yang hanya dipakai sebagai tipe dan mengubahnya menjadi import type. Kompiler kemudian menghapusnya saat kode dibangun.

Konten teknis (SKILL.md asli)

Teks asli dari pembuat, dalam bahasa Inggris, langsung dari 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

Pertanyaan umum

Apa fungsi import type?

Ini memberi tahu kompiler bahwa impor tersebut dihapus saat build, sehingga tidak ada modul runtime yang dimuat.

Apa itu verbatimModuleSyntax?

Itu adalah pengaturan TypeScript 5 yang menerapkan aturan ini secara otomatis, menurut skill.

Bisakah ini membantu dependensi sirkular?

Skill menyatakan dependensi sirkular yang dapat dihindari bisa dikurangi dengan memakai impor khusus tipe.

Detail

Deskripsi asli dari pembuat

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

Popularitas

Bintang GitHub
75k
Peringkat
#3067
Lisensi
MIT
Diperbarui
31/10/2026

Apakah skill ini berguna?

0

Masuk untuk memberi suara.

Komentar

  • …

Skill lain dari repositori ini

Skill serupa