-
-
Notifications
You must be signed in to change notification settings - Fork 32.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[core] Use boolean type for ListItem prop instead of 'false' #23338
Conversation
Fix checking error
Update my fork
This can be considered better than before but |
@eps1lon you could still accept the button props if you assign the value of button directly as <ListItem
button
onClick={e => ....} // `e` variable has `HTMLDivElement` type
/>
<ListItem
button={boolValue} // or `false`
onClick={e => ....} // `e` variable has `HTMLLIElement` type
/> That's why i changed the type order of |
What if |
But not always the same. The reasons why So, if you want get some I think this is better, cz it can assign the button variable dynamically. Unlike the old one that can only receive static value |
You're trading soundness. Whether that is "better" depends on how sound you want your types to be. You could achieve the same right now by passing |
For context, in #13597, we discuss breaking down the ListItem component into smaller components. It frees us from this problem. <nav>
<List>
<ListItem>
<ListItemButton component={NavLink}>
Foo
</ListItemButton>
<ListItemSecondaryAction>
Bar
</ListItemSecondaryAction>
</ListItem>
</List>
</nav> |
@ricosandyca Would it solve #14971? If it does, trading soundness could make sense for an issue with 35 upvotes. Maybe we should add a test case that illustrates the fix? |
@oliviertassinari i think it would, and for the test case i think it would be great |
💯 for accepting the changes if:
@eps1lon What do you think? |
It doesn't fix it. It just silences the error which can already be achieved by passing I already know that people don't want to do it because of "type casting is bad" but type casting isn't bad inherently. It's only bad if it leads to unsound types and is effectively equivalent to this change proposed here. But maybe I'm wrong but we can only check that if we have a type test for using HTMLListElement props on |
Should we close the pull request? |
Sometimes, we might need to assign button type as boolean. Last time i tried conditional variable passed to button prop. Something like this
But i got an error type caused type boolean isn't assignable to type
true
orfalse
For #14971