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(typescript): missing generic parameter of React.RefObject #1536

Merged

Conversation

fabb
Copy link
Contributor

@fabb fabb commented Sep 5, 2023

What:

Adds the generic type parameter for React.RefObject.

Why:
Fixes #1536
In @types/react, the type definition looks like this:

    interface RefObject<T> {
        readonly current: T | null;
    }

This means the T generic parameter needs to be set mandatorily.

In case skipLibCheck is not set to true, this causes a typescript type error:

../../node_modules/downshift/typings/index.d.ts:112:9 - error TS2314: Generic type 'RefObject<T>' requires 1 type argument(s).

112   ref?: React.RefObject
            ~~~~~~~~~~~~~~~

How:

I've added any as type parameter, which is not ideal but avoids adding a generic type parameter to the parent types (e.g. GetRootPropsOptions).

Open for better suggestions.

Checklist:

  • Documentation N/A
  • Tests N/A
  • TypeScript Types
  • Flow Types N/A
  • Ready to be merged

@fabb
Copy link
Contributor Author

fabb commented Sep 5, 2023

related to #1521

@silviuaavram
Copy link
Collaborator

@fabb thank you for the changes.

Do you think that the original proposed suggestion would be better? The one from the mentioned issue.

export interface GetRootPropsOptions<E extends HTMLElement> {
  refKey?: string
  ref?: React.Ref<E>
}

@fabb
Copy link
Contributor Author

fabb commented Sep 6, 2023

Yes that would probably be better.

@silviuaavram
Copy link
Collaborator

The HTML element proposal will not work with React Native. I believe that having any at the moment is good enough to unblock us, and the overall types are already an improvement over the previous ones. If anyone can propose a better way with generics, we can change it later.

@silviuaavram silviuaavram changed the title Fix missing generic parameter of React.RefObject fix(typescript: missing generic parameter of React.RefObject Sep 20, 2023
@silviuaavram silviuaavram changed the title fix(typescript: missing generic parameter of React.RefObject fix(typescript): missing generic parameter of React.RefObject Sep 20, 2023
@silviuaavram silviuaavram merged commit bc7639c into downshift-js:master Sep 20, 2023
2 checks passed
@github-actions
Copy link

🎉 This PR is included in version 8.1.1 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants