Skip to content

Conversation

@8Crafter
Copy link
Contributor

@8Crafter 8Crafter commented Sep 9, 2025

The type React.NamedExoticComponent does not exist, but React.ElementType does exist and works exactly how it needs to for what that non-existent type is being used for.
This is a necessary fix to fix the autocompletion of properties for the react components.

…ompletion.

The type `React.NamedExoticComponent` does not exist, but `React.ElementType` does exist and works exactly how it needs to for what that non-existent type is being used for.
@8Crafter
Copy link
Contributor Author

8Crafter commented Sep 9, 2025

To anyone seeing this who is not a maintainer of this project, if this still hasn't been merged when you see this, then you can use this type declaration as a temporary fix until it is merged:

declare global {
    namespace React {
        /**
         * An alias for {@link React.ElementType | React.ElementType\<P\>} to fix the component types of {@link https://www.npmjs.com/package/@szhsin/react-menu | @szhsin/react-menu}.
         */
        export type NamedExoticComponent<P = any> = React.ElementType<P>;
    }
}

@szhsin
Copy link
Owner

szhsin commented Sep 10, 2025

Did you have @types/react installed in your project? React.NamedExoticComponent has been around since React 16 and is still included in @types/react up through the latest v19. I’m not seeing an issue here.

@szhsin
Copy link
Owner

szhsin commented Sep 15, 2025

@Andexter8 Since you also raised #1591, I assume this PR is related to using the package with Preact, which explains why NamedExoticComponent does not exist. It looks like the typings in preact/compat only include ForwardRefExoticComponent.

A proper fix to the issue is likely to replace all instances of React.NamedExoticComponent with React.ForwardRefExoticComponent. This ensures the types are supported in both React and Preact.

If that resolves the issue, please update your PR with the change.

@8Crafter
Copy link
Contributor Author

I will try that tomorrow.

@szhsin
Copy link
Owner

szhsin commented Nov 24, 2025

@8Crafter since I haven’t heard back from you, I’ve updated the PR as previously discussed

@szhsin szhsin merged commit 57e19ff into szhsin:master Nov 24, 2025
@szhsin szhsin changed the title Fix non-existent type references Switch to ForwardRefExoticComponent for Preact compatibility Nov 24, 2025
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.

2 participants