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

Props being inferred as any since v7 #5042

Open
cascornelissen opened this issue Aug 21, 2024 · 6 comments
Open

Props being inferred as any since v7 #5042

cascornelissen opened this issue Aug 21, 2024 · 6 comments

Comments

@cascornelissen
Copy link

Describe the bug
A number of props are inferred as any after updating react-datepicker to v7. This makes it impossible to extend the DatePicker component's props for a component that renders a DatePicker.

To Reproduce
Install react-datepicker v7 (7.3.0 at the moment of writing) and let TypeScript infer types for props that are not directly configured in the DatePickerProps interface.

import React from 'react';
import DatePicker, { DatePickerProps } from 'react-datepicker';

// These get inferred as `any`
type A = React.ComponentProps<typeof DatePicker>['minDate'];
type B = DatePickerProps['maxDate'];
type C = DatePickerProps['dateFormatCalendar'];

// These work
type D = DatePickerProps['open'];

Expected behavior
The type is correctly inferred.

Screenshots
image
image

Additional context
TypeScript 5.5.4

@floriancargoet
Copy link

floriancargoet commented Oct 17, 2024

I have the same issue.
I believe it's because the portal.d.ts file is missing. This introduces an any in the types which breaks DatePickerProps.

When building react-datepicker myself, portal.d.ts is generated (and fixes my project if I copy it to my node_modules/react-datepicker/dist). I don't know why it's missing from the NPM package.

@floriancargoet
Copy link

It looks like it was reported here: #5129
And it was fixed 2 days ago: 1b13e38

@Christoffer-M
Copy link

Christoffer-M commented Oct 17, 2024

@floriancargoet Do you know if there is a temporary way to fix this until the a new version with the fix is released? This is causing build errors, so cant release. I assume that building it myself wont work since it will fail when deploying it via pipelines.

@floriancargoet
Copy link

@Christoffer-M in my project, locally, I copy in node_modules/react-datepicker/dist the portal.d.ts I got by cloning & building react-datepicker.
For an automated build, I'm thinking of using https://www.npmjs.com/package/patch-package while waiting for a release.

@martijnrusschen
Copy link
Member

martijnrusschen commented Oct 17, 2024 via email

@Christoffer-M
Copy link

Christoffer-M commented Oct 17, 2024

@martijnrusschen You're a legend, thanks! 👍

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

No branches or pull requests

4 participants