polymorphic-component
Installation
SKILL.md
polymorphic-component
Implements the as prop pattern with full TypeScript safety — correct HTML prop inference per element, working ref types, and no prop leakage. Skips basics; addresses only the parts that cause real pain.
Phase 1 — Discover
Establish before writing anything:
- Does the component need ref forwarding? (If yes, the generic chain is different — see Phase 3.)
- Does the component have own props that may conflict with native HTML props? (e.g., a
sizeprop clashing with<input size>) - What's the default element when
asis omitted? - Should
asaccept custom components, or only HTML element strings? (Accepting both requires a union constraint.)