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

fix: Missing ForwardRefExoticComponent and RefAttributes types in compat #3996

Merged
merged 4 commits into from
May 17, 2023

Conversation

rschristian
Copy link
Member

Fixes #3759, though only the immediate issue. Popper from @mui/material still does not type check correctly -- I added about a half-dozen types in compat and still couldn't get any type errors. We're missing a fair few things I guess, but that lib is such a maze of imports that I couldn't even track down all of what we were missing. Issue for another day I think?

Adapted from React's types here and here


To provide a simpler and more cut down reproduction than the original issue provided, the following example React library will generate the following types:

import { forwardRef } from 'react';

export const MyInput = forwardRef<HTMLInputElement, { label: string }>(function MyInput(props, ref) {
    return (
        <label>
            {props.label}
            <input ref={ref} />
        </label>
    );
});
export declare const MyInput: import("react").ForwardRefExoticComponent<{
    label: string;
} & import("react").RefAttributes<HTMLInputElement>>;

Aliasing react to preact/compat using "paths" in a tsconfig.json would convert the type of MyInput into any as ForwardRefExoticComponent and RefAttributes could not be found.

@coveralls
Copy link

coveralls commented May 7, 2023

Coverage Status

Coverage: 99.707%. Remained the same when pulling a24d26b on types/compat-forward-ref-exotic-component into 19f4176 on master.

@robertmaier
Copy link

This is great :) I ran into the same problem integrating a React library today. Exchanging the types locally works as expected.

@JoviDeCroock Are there any plans to include this in one of the upcoming releases?

@JoviDeCroock
Copy link
Member

JoviDeCroock commented May 17, 2023

@robertmaier people part of the org can merge their own PR's, I gave the green light by approving it but Ryan can merge himself when he feels like it :) it will then be part of a release later on.

Happy to hear the PR helps you!

@rschristian
Copy link
Member Author

Whoops, totally forgot about this. Will merge in a minute.

@rschristian rschristian merged commit b69428e into master May 17, 2023
@rschristian rschristian deleted the types/compat-forward-ref-exotic-component branch May 17, 2023 15:03
@JoviDeCroock JoviDeCroock mentioned this pull request May 19, 2023
JoviDeCroock added a commit that referenced this pull request Jan 24, 2024
JoviDeCroock added a commit that referenced this pull request Jan 24, 2024
* backport #4016

* backport #3996

* backport #4017

* backport #4019

* backport #4020

* backport #4026

* backport #4028
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.

(preact/compat types) Add ForwardRefExoticComponent
4 participants