Typescript React Component Props Error

Hi, I'm trying to implemented an AuthenticatedRoute component. I'm wrapping the Route component from react-router-dom. Getting a frustrating TS error. I just don't understand how to fix it, can anyone help?
12 Replies
cje
cjeā€¢2y ago
Use composition instead That way the only prop you need is children
Unknown User
Unknown Userā€¢2y ago
Message Not Public
Sign In & Join Server To View
dinislam
dinislamā€¢2y ago
Is there a way to inject the route props at the same time? history, location, match etc. By that I mean from within the AuthenticatedRoute component add extra props to the Component
cje
cjeā€¢2y ago
probably not if you want that, i think you'll need to figure out your generic its going to be hell though
dinislam
dinislamā€¢2y ago
Ahh šŸ˜¦
cje
cjeā€¢2y ago
tbh either find a library that does this or prepare to enter generics hell
dinislam
dinislamā€¢2y ago
Would the future ā€œsatisfiesā€ keyword help here?
cje
cjeā€¢2y ago
you could look at the typedefs for tanstack router and other similar libraries
dinislam
dinislamā€¢2y ago
Sounds good
cje
cjeā€¢2y ago
but its going to be waaaay more complex than what you had going in your op
dinislam
dinislamā€¢2y ago
The generic seems straightforward conceptually. I want ā€œcomponentPropsā€ to be the same type as the props for the ā€œcomponentā€. Strange that itā€™s so hard in practice to do
Unknown User
Unknown Userā€¢2y ago
Message Not Public
Sign In & Join Server To View
Want results from more Discord servers?
Add your server