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(types): PropsWithChildren not compatible with React 17 #1947

Merged
merged 1 commit into from
Oct 18, 2023

Conversation

binhpv
Copy link
Contributor

@binhpv binhpv commented Oct 18, 2023

Context

The newest version of react-day-picker is not compatible with @types/react 17.

Analysis

In the last version of the library some props were declare with PropsWithChildren. This interface originally in @types/react 17 is:

    type PropsWithChildren<P> = P & { children?: ReactNode | undefined };

but in @types/react version 18 it has changed to

    type PropsWithChildren<P = unknown> = P & { children?: ReactNode | undefined };

Please note the new default of unknown. This mean new typing relies on @types/react@18 doesn't have to provide the typing when using PropsWithChildren, however it is a must with @types/react@17. The usage of PropsWithChildren in react-day-picker without the argument for the generic type make it incompatible with projects using React 17.

Solution

When using PropsWithChildren, always include argument for the generic typing so that it's also compatible with React 17 codebase.
In this PR I also change some places where the prop is declare as equal to PropsWithChildren (e.g. MonthsProps) to explicitly type as { children: ReactNode }. This ensure that children is required, and there is no need to rely on PropsWithChildren since there is no additional prop.

@gpbl gpbl merged commit db260be into gpbl:main Oct 18, 2023
10 checks passed
@gpbl
Copy link
Owner

gpbl commented Oct 18, 2023

Thanks so much @binhpv! I completely missed that. Publishing soon on npm...

@gpbl gpbl changed the title Fixing incompatible usage of PropsWithChildren so that typing works with React 17 fix(types): PropsWithChildren not compatible with React 17 Oct 18, 2023
@binhpv
Copy link
Contributor Author

binhpv commented Oct 18, 2023

Thanks @gpbl for your quick follow up. Cheers!

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