-
-
Notifications
You must be signed in to change notification settings - Fork 32.2k
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
[TypeScript] Error: TransitionComponent type not assignable to 'ForwardRefExoticComponent' #17542
Comments
👋 Thanks for using Material-UI! We use GitHub issues exclusively as a bug and feature requests tracker, however, For support, please check out https://material-ui.com/getting-started/support/. Thanks! If you have a question on StackOverflow, you are welcome to link to it here, it might help others. |
I just noticed that I can toggle between JavaScript and TypeScript code in the Material UI demo pages. It seems that I have to assign a type import { TransitionProps } from '@material-ui/core/transitions';
const Transition = React.forwardRef<unknown, TransitionProps>((props, ref) => <Slide direction="up" ref={ref} {...props} />);
... App runs without any errors. This issue can be kept closed. |
Please note that i used |
It worked for me like this: const Transition = React.forwardRef<
unknown,
TransitionProps & {
children?: React.ReactElement
}
>((props, ref) => {
return <Slide direction='up' ref={ref} {...props} />
}) I added |
When trying @ApayRus solution above I ran into "Component definition is missing display name" as the example does not include the named function from the original code example. However the solution is correct, keeping the named function call within the forwaredRef hook, but adding the const Transition = React.forwardRef(function Transition(
props: TransitionProps & {
children?: React.ReactElement;
},
ref: React.Ref<unknown>
) {
return <Slide direction="up" ref={ref} {...props} />;
}); |
Current Behavior 😯
Passing a
forwardRef
transition component to aTransitionComponent
prop
inDialog
component throws type error:Type 'ForwardRefExoticComponent<RefAttributes<{}>>' is not assignable to type 'ComponentType<TransitionProps>'. Type 'ForwardRefExoticComponent<RefAttributes<{}>>' is not assignable to type 'FunctionComponent<TransitionProps>'. Types of property 'defaultProps' are incompatible. Type 'Partial<RefAttributes<{}>>' has no properties in common with type 'Partial<TransitionProps>'.
Expected Behavior 🤔
TransitionComponent
should have type support forForwardRefExoticComponent
Steps to Reproduce 🕹
link to codesandbox
Context 🔦
Migrating from JavaScript code to TypeScript. Currently using normal function component to bypass this error - this results in working app with expected warning
Did you accidentally use a plain function component for an element instead?
that I'm ignoring for now.Your Environment 🌎
The text was updated successfully, but these errors were encountered: