Chuyển đến nội dung
Skillpedia
Lập trình chung75k · #3006

runtime-validation

Skill này làm gì

Skill này tìm những chỗ ứng dụng nhận dữ liệu từ mạng, bộ nhớ, cài đặt môi trường hoặc biểu mẫu, rồi thêm kiểm tra lúc chạy bằng thư viện schema. Skill dành cho lập trình viên muốn ít lỗi do dữ liệu bất ngờ.

Khi nào nên dùng

  • ✓Khi bạn yêu cầu agent thêm kiểm tra cho dữ liệu đến từ API hoặc biểu mẫu.
  • ✓Khi ứng dụng hỏng vì API trả về hình dạng dữ liệu khác với dự kiến.
  • ✓Khi bạn rà soát mã đọc từ bộ nhớ cục bộ hoặc biến môi trường và muốn các giá trị đó được kiểm tra.

Liên kết skill

https://github.com/thedaviddias/Front-End-Checklist/blob/main/skills/runtime-validation/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/runtime-validation/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

“Ứng dụng của tôi hỏng khi API gửi dữ liệu hơi khác so với dự kiến. Bạn có thể thêm kiểm tra ở những điểm dữ liệu đi vào không?”

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

Cách hoạt động

Agent tìm những chỗ dữ liệu vào ứng dụng, như các lệnh gọi fetch, lần đọc bộ nhớ cục bộ và biểu mẫu gửi đi. Agent thêm schema, ví dụ với Zod, để kiểm tra hình dạng dữ liệu và đưa ra lỗi rõ ràng khi nó không khớp.

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.

Validate external data at runtime with a schema library

TypeScript gives you confidence at compile time, but data from the network, user input, and storage arrives at runtime as raw, untyped values. A backend schema change, a misconfigured API, or malicious input can produce data that does not match your TypeScript types — and the compiler will never warn you. Runtime validation with a schema library catches these mismatches at the boundary, surfaces clear error messages, and prevents type-unsafe data from propagating through your application.

Quick Reference

  • TypeScript types are compile-time only — they are completely erased at runtime
  • API responses can differ from their declared types without causing a compile error
  • A Zod schema simultaneously validates data and infers the TypeScript type
  • Validate at trust boundaries only — not inside every internal function call

Check

Identify all places in this code where external data enters the application (fetch calls, localStorage reads, env variable access, form submissions) and report which ones lack runtime schema validation.

Fix

Add Zod schemas to validate the external data entry points in this code. Show the schema definition, the validated type inference, and where to call .parse() or .safeParse().

Explain

Explain why TypeScript types do not protect against runtime data mismatches, how Zod bridges compile-time and runtime safety, and when to use .parse() versus .safeParse().

Code Review

Review all external data entry points in this file: API calls, storage reads, environment variable access, and form handling. Flag any location where data is cast to a TypeScript type without a preceding runtime validation step.


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

Rule page: https://frontendchecklist.io/rules/javascript/runtime-validation

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

Vì sao kiểu TypeScript là chưa đủ?

Skill nói kiểu TypeScript bị xóa khi mã chạy, nên không thể kiểm tra dữ liệu thật lúc chạy.

Nên đặt kiểm tra ở đâu?

Skill nói nên kiểm tra tại các ranh giới tin cậy, nơi dữ liệu bên ngoài đi vào, thay vì ở mọi hàm nội bộ.

Schema mang lại gì cho tôi?

Skill nói schema Zod kiểm tra dữ liệu và đồng thời cung cấp kiểu TypeScript tương ứng.

Chi tiết

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

Use when reviewing code that calls fetch(), reads from localStorage, accesses process.env, or processes form submissions without explicitly validating the incoming data shape.

repo: thedaviddias/Front-End-Checklist

Độ phổ biến

Sao GitHub
75k
Vị trí xếp hạng
#3006
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ự