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

Types: Missing MemoExoticComponent in preact/compat #3897

Closed
1 task done
rschristian opened this issue Feb 15, 2023 · 0 comments · Fixed by #3898
Closed
1 task done

Types: Missing MemoExoticComponent in preact/compat #3897

rschristian opened this issue Feb 15, 2023 · 0 comments · Fixed by #3898

Comments

@rschristian
Copy link
Member

rschristian commented Feb 15, 2023

  • Check if updating to the latest Preact version resolves the issue

Describe the bug
The React namespace in preact/compat is missing a definition for MemoExoticComponent so users who rely on that and use preact/compat's types instead of React's run into the issue where their components are typed as any.

https://twitter.com/Sawtaytoes/status/1625959909752709121

To Reproduce

The following example React library will generate the following types:

import { memo } from 'react';

function MyComponent() {
    return <h1>Hello World!</h1>;
}

export const MyMemoComponent = memo(MyComponent);
export const MyMemoComponent: import("react").MemoExoticComponent<typeof MyComponent>;
declare function MyComponent(): JSX.Element;
export {};

If we were to alias react to preact/compat using "paths" in a tsconfig.json in a consumer of the above library, that would essentially become this:

export const MyMemoComponent: import("preact/compat").MemoExoticComponent<typeof MyComponent>;
declare function MyComponent(): JSX.Element;
export {};

However, as there is no MemoExoticComponent, MyMemoComponent becomes typed as any.

Interestingly, TS doesn't throw an error when an aliased path is missing a member.

Expected behavior

Should distribute MemoExoticComponent

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 a pull request may close this issue.

1 participant