A practical walkthrough of building a typed polymorphic React component using TypeScript generics. The author explores why a naive intersection type approach fails to narrow props correctly, discovers that wrapping ComponentProps in a mapped type (or using Omit with any key) forces TypeScript to materialize the generic after inference, and arrives at a working implementation where the allowed props are strictly determined by the value of the `as` prop.
144.4K Impressions1 Comment