Skip to content
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

Add missing PropsWithRef type to fix #4293 #4333

Closed

Conversation

ryanlchan
Copy link

#4271 introduces a bug where some types are incorrectly resolved.

Compared to the original types/react implementation, #4271's is missing an enclosing PropsWithRef in the return statement. The problems appear to resolve after restoring that line.

Fixes #4293

@@ -178,7 +178,7 @@ declare namespace React {
C extends ComponentType<any> | keyof JSXInternal.IntrinsicElements
> = C extends new (props: infer P) => Component<any, any>
? PropsWithoutRef<P> & RefAttributes<InstanceType<C>>
: ComponentProps<C>;
: PropsWithRef<ComponentProps<C>>;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bear with me as I'm doing this from my phone, but I don't see PropsWithRef defined anywhere?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah - that's totally my miss. I'm still trying to figure out problems with other MUI components on another branch and didn't see that I'd missed copying the type here. Unfortunately, after copying, it doesn't appear to resolve the issue. I'll keep digging. Sorry for that!

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

After further investigation, I think this change + the types/react PropsWithRef definition does fix the original issue.

However, it also revealed a related problem: several MUI component props refer to React types that are not currently supported by compat (e.g. React.InputHTMLAttributes). The simple fix would be to alias those to HTMLAttributes, which captures all valid HTML attributes already (per #4202). A more React-y way would be to add React's stricter tag-based props there's quite a lot of them and it this seems like a big change in typing complexity over the current state.

@rschristian do you have a preference?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Aliasing to the looser HTMLAttributes sounds fine for the time being, if you're willing.

Indeed, supporting all of those per-tag attributes would be a PITA, though (eventually) desirable I guess.

@ryanlchan ryanlchan closed this Apr 1, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Typescript issues in 10.19.4+ with @mui/material
3 participants