type-coercion
できること
このスキルは、思わぬ結果を生むおそれのある比較や変換を JavaScript のコードで確認します。隠れたバグを減らしたい開発者向けです。
使う場面
- ✓JavaScript のコードで、厳密でない == や != を使っているとき。
- ✓テキストと数値を、意図しない形で足し合わせているとき。
- ✓スクリプトの型の扱いを、もっと明確にするようコードレビューで求められたとき。
スキルのリンク
https://github.com/thedaviddias/Front-End-Checklist/blob/main/skills/type-coercion/SKILL.mdコピーしてAI(Claude、ChatGPT、Cursor)に貼り付け、指示に従うよう頼んでください。
使い方
いちばん簡単な方法:メッセージをコピーしてAIに貼り付けるだけ。AIがスキルを読んで指示に従います。
貼り付け用メッセージ
Claude Code、Codex、Cursorの場合:プロジェクトのフォルダで実行するとスキルがインストールされます。
SKILL.mdをダウンロードして、エージェントのスキル用フォルダに入れてください。
AIへの頼み方の例
“私の JavaScript は、ときどき値の比較を誤ります。緩い比較を見つけて、厳密な比較に直してもらえますか。”
毎週5つの新しいスキル。1分で読めます。
仕組み
エージェントは、緩い等価比較と、危険な型の混在した演算を見つけます。それらを厳密な比較と、明示的な変換に置き換えます。
技術的な内容(元のSKILL.md)
作者による元のテキスト(英語)をGitHubからそのまま表示しています。
Avoid implicit type coercion
JavaScript's implicit type coercion produces results that look like bugs to anyone who doesn't know the exact coercion rules. == comparisons with mixed types silently convert values in ways that fail to catch genuine errors. Explicit conversions make code intent clear and catch real type mismatches at the point where they occur.
Quick Reference
- Always use === and !== instead of == and !=
- Convert types explicitly with Number(), String(), Boolean(), parseInt()
- Be careful with + operator — it concatenates strings but adds numbers
- Use Array.isArray() instead of typeof for array checks
Check
Find all uses of == and != (non-strict equality) in this file. Also look for implicit type conversions from + operator and other coercion traps.
Fix
Replace all == with === and != with !==. Add explicit type conversions where mixed types are intentionally compared.
Explain
Explain JavaScript's implicit type coercion rules, why == is problematic, and how to write safe type comparisons.
Code Review
Review scripts, client components, and browser execution paths related to Avoid implicit type coercion. Flag exact imports, event handlers, runtime side effects, or blocking operations that violate the rule, and state how the change should be verified in the browser.
For full implementation details, code examples, and framework-specific guidance,
see references/rule.md.
Rule page: https://frontendchecklist.io/rules/javascript/type-coercion
よくある質問
== はなぜ問題なのですか?
比較の前に値を自動的に変換するため、本当の間違いを隠し、結果を予測しにくくするからです。
配列かどうかを確かめる安全な方法は何ですか?
typeof ではなく Array.isArray() を使うことを、このスキルは勧めています。
型はどのように変換すべきですか?
Number()、String()、Boolean()、parseInt() などの明示的な関数を使うべきです。
詳細
作者による元の説明
Use when reviewing scripts, client components, bundles, or runtime behavior related to Avoid implicit type coercion. Inspect both source code and the browser execution path so fixes target the real bottleneck or bug.
人気
- GitHubのスター
- 75k
- ランキング
- #3066
- ライセンス
- MIT
- 更新日
- 2026/10/31
コメント
- …
このリポジトリの他のスキル
frontendchecklist
75kコマンドラインツールを使って、フロントエンドのコードとライブページを、アクセシビリティ、速度、SEO、セキュリティに関する380以上のルールと照らし合わせて確認します。
frontend-checklist-global
75kフロントエンドのプロジェクトを、386のFront-End Checklistのルールすべてと照らし合わせて監査し、見つかった問題ごとに具体的な修正方法を示します。
404-page
75k見つからないページの画面に役立つリンクがあり、本物の404ステータスを返すかを確認し、迷った訪問者が目的のページを見つけられるようにします。
about-page
75kサイトの運営者が誰かを説明する、分かりやすいAboutページがあるかを確認し、訪問者と検索エンジンからの信頼を高めます。
似ているスキル
diffs
394k編集内容の実際の共有可能な差分を、手書きの要約ではなく、ビューアーのリンクや画像ファイルとして作成するようエージェントを支援します。
coding-agent
394kCodex、Claude Code、OpenCodeに大きめのコーディング作業をバックグラウンドのワーカーとして渡し、その進捗を確認するようエージェントを支援します。
gh-issues
394kGitHubのイシューを探し、取り組むものを選び、修正を含むプルリクエストを開くようエージェントを支援します。レビューコメントへの対応も含みます。