Forum

Publications, Forum Activity, and Verified Credentials

How to properly type dynamic React props in TypeScript?

I am building a reusable `Card` component that can render as an `a` tag, a `button` tag, or a custom Next.js `Link` based on an `as` prop. I am struggling to get the TypeScript typing correct so that standard attributes (like `href` for links, `type` for buttons) are auto-completed and typesafe. Can someone show me a clean way to achieve this?

0 replies0 likes