Chuyển đến nội dung
Skillpedia
Website và giao diện (frontend)75k · #2950

no-explicit-any

Skill này làm gì

Skill này rà soát các tệp TypeScript để tìm kiểu any, vì nó tắt việc kiểm tra kiểu. Skill dành cho lập trình viên muốn TypeScript bắt được nhiều lỗi sớm hơn.

Khi nào nên dùng

  • ✓Khi bạn yêu cầu agent rà soát một tệp TypeScript về các vấn đề an toàn kiểu.
  • ✓Khi linter báo cảnh báo về kiểu any và bạn muốn sửa đúng cách.
  • ✓Khi một hàm xử lý dữ liệu từ bên ngoài ứng dụng và bạn muốn kiểm tra dữ liệu đó trước khi dùng.

Liên kết skill

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

Sao chép rồi dán vào AI của bạn (Claude, ChatGPT hoặc Cursor) và nhờ nó làm theo hướng dẫn.

Cách dùng

Cách dễ nhất: sao chép tin nhắn và dán vào AI của bạn. AI sẽ đọc skill và làm theo hướng dẫn.

Tin nhắn có sẵn để dán

Hãy dùng skill này để giúp tôi: https://github.com/thedaviddias/Front-End-Checklist/blob/main/skills/no-explicit-any/SKILL.md Đọc tệp SKILL.md tại liên kết đó và làm theo hướng dẫn cho việc của tôi.
Bạn muốn AI tự tìm những skill như thế này?Cài MCP Skillpedia miễn phí: chỉ một dòng, và AI sẽ tìm trong 15.000+ skill trước mỗi việc.Cài đặt trong 1 phút →

Ví dụ cách nhờ AI

“Bạn có thể rà soát các tệp TypeScript của tôi và thay các kiểu any bằng những kiểu an toàn hơn không?”

5 skill mới mỗi tuần. Đọc chỉ 1 phút.

Cách hoạt động

Agent tìm mọi chỗ dùng any, kể cả các trường hợp ngầm định và khẳng định kiểu. Agent gợi ý thay thế như unknown, generic hoặc xác thực, và chỉ ra các kiểm tra cần thiết ở nơi mỗi giá trị được dùng.

Nội dung kỹ thuật (SKILL.md gốc)

Lấy nguyên văn từ GitHub, do tác giả viết bằng tiếng Anh.

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

Câu hỏi thường gặp

Khác nhau giữa any và unknown là gì?

any tắt hoàn toàn việc kiểm tra, còn unknown buộc phải kiểm tra kiểu trước khi dùng giá trị.

Có bao giờ dùng khẳng định kiểu là ổn không?

Skill nói khẳng định kiểu đôi khi có thể chấp nhận, nhưng nó nguy hiểm khi dùng để che giấu vấn đề thật.

Vì sao cần kiểm tra dữ liệu ở biên của ứng dụng?

Skill khuyên kiểm tra dữ liệu bên ngoài bằng thư viện xác thực như Zod, thay vì khẳng định kiểu của nó.

Chi tiết

Mô tả gốc của tác giả

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

Độ phổ biến

Sao GitHub
75k
Vị trí xếp hạng
#2950
Giấy phép
MIT
Cập nhật
31/10/2026

Skill này có hữu ích không?

0

Đăng nhập để bình chọn.

Bình luận

  • …

Thêm skill từ kho mã này

Skill tương tự