DEV Community


Discussion on: The 10 Component Commandments

asherccohen profile image
Asher Cohen

This was the one I preferred. But in a non-typescript world that would require a lot of conditions to return the right element type.

Am I right?

selbekk profile image
selbekk Author

Good question! It’s not a very easy type to get right, especially if you want the correct props of the as element to be applied as well. It is doable though, with a drizzle of keyof and some other ts ninja tricks. I’m not a great TS dev yet, and I’m on my phone atm.

There is lots of prior art here - look at reach UI or styled components’types for possible impoementations