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ā€¢3y ago
Use composition instead That way the only prop you need is children
Unknown User
Unknown Userā€¢3y ago
Message Not Public
Sign In & Join Server To View
dinislam
dinislamOPā€¢3y 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ā€¢3y ago
probably not if you want that, i think you'll need to figure out your generic its going to be hell though
dinislam
dinislamOPā€¢3y ago
Ahh šŸ˜¦
cje
cjeā€¢3y ago
tbh either find a library that does this or prepare to enter generics hell
dinislam
dinislamOPā€¢3y ago
Would the future ā€œsatisfiesā€ keyword help here?
cje
cjeā€¢3y ago
you could look at the typedefs for tanstack router and other similar libraries
dinislam
dinislamOPā€¢3y ago
Sounds good
cje
cjeā€¢3y ago
but its going to be waaaay more complex than what you had going in your op
dinislam
dinislamOPā€¢3y 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ā€¢3y ago
Message Not Public
Sign In & Join Server To View
Want results from more Discord servers?
Add your server