-
-
Notifications
You must be signed in to change notification settings - Fork 32.5k
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
[Tabs] Issues with onChange TypeScript types #17454
Comments
I think there's actually a lot more going on across many components. I'm encountering the same issue in a number of places. For example using function onClick(event: React.MouseEvent<HTMLButtonElement>) {}
return (<Link component="button" onClick={onClick}>
Hey!
</Link>); has error:
Sample: https://codesandbox.io/s/create-react-app-with-typescript-ztfq4 /cc @ypresto |
Updated title to reflect that the issue isn't just within |
@ianschmitz I can't reproduce the issue on your codesandbox. Can you? |
I'm also getting the following error:
I think the key part of this error is the expected type: The & should be an | it seems as there's no valid function that would match both of those function signatures at the same time that I can see. |
Having the same error, does anyone have a better fix/hack for it than this?
|
We are also having this issue
But we'd like a better solution, this doesn't feel good |
@ianschmitz I have seen the exact same bug in #20191. What do you think of this patch #20191 (comment)? |
@oliviertassinari I thought i was going crazy here is a sandbox showing 2 approaches both breaking something and fixing something else. |
@oliviertassinari a quick glance seems like that would improve things. To be honest some of those types make me go cross eyed when i read them so it's hard to say without writing out a bunch of test cases 😛 |
I'm just doing this right now. It's messy but I don't really know a better solution interface TabsPropsFixed extends Omit<TabsProps, "onChange"> {
onChange:
| ((event: ChangeEvent<{}>, value: any) => void)
| ((event: FormEvent<HTMLButtonElement>) => void);
}
export const Tabs: React.FC<TabsPropsFixed> = props => <Tabs {...props}/> |
Good news: The suggested type was definitely wrong on our part. We're not creating a custom, react change event in the Tabs component. We're simply passing along whatever event triggered the change in value. I won't go into detail what specific type of events this could be so that we're not needlessly restricting our implementation. It's a bit unfortunate since it's highly unlikely that you ever relied on specifics of I suggest using |
@eps1lon I still do have the issue. I tried both solutions, nothing works for me. material-ui@4.11.0 UPD: I just realised that this fix was merged into next branch that is 5.* alpha. Is it possible to have this fix cherry-picked to 4.* by any chance? |
We're only backporting important or security fixes at this stage. |
Were you able to figure this out? |
This worked for me |
Still have this issue, and when I am reading "event.target.value" or "event.currentTarget.value" there is "undefined" or "null". |
export interface ITabsProps extends Omit<TabsProps, 'onChange' | 'textColor'> { @iiskaandar I used this |
I was able to do this:
|
This comment has been minimized.
This comment has been minimized.
Still an issue, and none of the above proposed solutions worked. |
@nick-buzzy do you have a reproduction with v5? |
No I am using the latest stable version, 4.11. |
Yeah I'm running in to this issue with the tabs component with these mui versions {
"@mui/core": "^5.0.0-alpha.51",
"@mui/icons-material": "^5.0.4",
"@mui/lab": "^5.0.0-alpha.51",
"@mui/material": "^5.0.4",
"@mui/styled-engine": "npm:@mui/styled-engine-sc@latest",
"@mui/styles": "^5.0.1",
"@mui/system": "^5.0.4",
"@mui/x-data-grid": "^5.0.0-beta.4",
} |
I know this is a few years old now, but I just came across this issue in our codebase and this is what I was able to come up with without having to create an intermediate type or wrapping the component. const handleOnChange = (
event?: FormEvent<HTMLButtonElement> | ChangeEvent<unknown>,
value?: any, // You can set this to whatever you're actually expecting
) => {
// do things
}; |
Current Behavior 😯
Wrapping the
Tabs
component results in TypeScript emitting the wrong types for theonChange
prop:The same problem looks to be appearing for
action
. It appears to be intersecting the types fromButtonBase
s props. Maybe a union type was intended?Expected Behavior 🤔
The type of
TabsProps.onChange
should be((event: React.ChangeEvent<{}>, value: any) => void) | undefined
. I believe this regression may have been caused by #16487.Steps to Reproduce 🕹
See https://codesandbox.io/s/upbeat-grass-gc0i9 for the TypeScript error and example wrapping of
Tabs
component.Context 🔦
It's quite common for us to wrap up the MUI components with our own customizations and export them as common components to use throughout our applications. In this case after upgrading MUI's minor version recently this started causing TypeScript errors everywhere we've used
Tabs
.Your Environment 🌎
The text was updated successfully, but these errors were encountered: