You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This approach allows me to have the types for row dynamically infered depending on the props I give to my Table component.
So when I use it like this:
constdata=[{id: 1,name: "John",},];exportconstParent=()=>{return(<div>{/* below, the `row` argument of the renderRow prop is automatically infered to { id: number; name: string; } */}<Tablerows={data}renderRow={(row)=><td>{row.name}</td>} /></div>);};
The problem is, as soon as I use styled around the Table component, I lose that inference
constStyledTable=styled(Table)``;constdata=[{id: 1,name: "John",},];exportconstParent=()=>{return(<div>{/* below, the `row` argument of the renderRow prop is instead infered to AnyObject */}<StyledTablerows={data}renderRow={(row)=><td>{row.name}</td>} /></div>);};
And if I remove the extends AnyObject from my Table component like this:
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
Hello!
I'm coming to you for help, as I am not sure if this is a bug, a limitation or just me that is not doing things correctly 🙂
Basically, I have a React component, which takes advantage of generic types, like this:
This approach allows me to have the types for
row
dynamically infered depending on the props I give to myTable
component.So when I use it like this:
The problem is, as soon as I use
styled
around theTable
component, I lose that inferenceAnd if I remove the
extends AnyObject
from myTable
component like this:Then
row
will be infered asunknown
Can somebody help me why this is happening, and if this can be solved somehow?
I made a small repro on TS Playground with all the necessary code.
Beta Was this translation helpful? Give feedback.
All reactions