-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
DesktopDatePickerProps<Date> error Type 'Date' does not satisfy the constraint 'never' in version 7.1.0 #12640
Comments
Hello @andylacko, I was unable to reproduce your issue. |
I'm also seeing the same issue. I simply took the Joy UI sample code for the date range picker (JoyUI Sample Code). I changed the date provider to be date-fns and used pro version (@mui/x-date-pickers-pro). As I was trying to create a standalone component I removed the wrapper components for JoyV6MultiInputRangeField as this is done elsewhere. I then removed the unused imports and the issue started appearing. By leaving the following unused import in the code, the issue goes away. If you remove it, the issue appears
|
@CWThomson Which adapter and where are you using in your application? TL/DR: I don't see a problem here, everything seems to work as expected. 👌 Are you by any chance building a component library and there is no place where a |
Thanks @LukasTy . I am building a component library and using tsup. Its in the build process this fails (Storybook works fine). Your explanation makes perfect sense. Storybook does initialize a LocalizationProvider with the AdapterDateFnsV3 adapter. As a component library, we leave the downstream app to be responsible for initializing the LocalizationProvider. Thanks for your help! |
@CWThomson does your library only support mui-x/packages/x-date-pickers/src/AdapterDateFnsBase/AdapterDateFnsBase.ts Lines 121 to 125 in b7848b4
|
Our component library is for internal use only so we've standardized on date-fns. Thanks for the tips, may be a better approach to main flexibility. |
I'm also seeing the same issue. With MUI X v7 and date-fns
Here is the code of my custom component, extending the default export interface CustomDatePickerProps<
TDate extends PickerValidDate,
TEnableAccessibleFieldDOMStructure extends boolean = false,
> extends DatePickerProps<TDate, TEnableAccessibleFieldDOMStructure> {
// custom properties here...
} function CustomDatePicker<TDate extends PickerValidDate, TEnableAccessibleFieldDOMStructure extends boolean = false>(
props: CustomDatePickerProps<TDate, TEnableAccessibleFieldDOMStructure>,
) {
// simplified version of my code (in real life I use styled to customize the style of DatePicker)
return <DatePicker {...props} />
} Usage: <CustomDatePicker<Date> // --> TS2344: Type Date does not satisfy the constraint never
value={new Date()}
/> Edit: declaring the specific module (cf. @LukasTy reply below) fix the issue. But I'm not sure to understand why. My React app is already using It was working well before with MUI X v6, without this fix. |
@guicara I tried reproducing your problem, but wasn't able to trigger the mentioned error if A minor nitpick regarding your wrapped component types: export interface CustomDatePickerProps extends DatePickerProps<Date, false> {
// custom properties here...
}
In v7 we have introduced more type safety, because prior to v7 you could use |
In v6, the type of the date was inferred from the props; // Invalid because `value` and `onChange` should have the same typing
<LocalizationProvider dateAdapter={AdapterDayjs]>
<DatePicker value={new Date()} onChange={(date: Dayjs) => {}} />
</LocalizationProvider> But it was not able to complain for the following code: // `value` and `onChange` are coherent, but they are not compatible with `AdapterDayjs`
<LocalizationProvider dateAdapter={AdapterDayjs]>
<DatePicker value={new Date()} onChange={(date: Date) => {}} />
</LocalizationProvider> This was super problematic because people tend to pass Our solution was to limit the valid types for the date to the one supported by the adapter(s) you imported. In your example, you are using It seems that you are importing it outside of the typescript project used to check the file that throws an error. You should be able to get rid of the error by adding the
@LukasTy I do agree that a section in the migration guide would be a nice addition |
Thank you for your help and replies. The issue was on my side due to a wird dependencies issues between the app consuming the design system and the design system itself.
Yes
Yes |
The issue has been inactive for 7 days and has been automatically closed. |
@guicara @andylacko I'm having the same issue, how did you fixed it? |
I've moved the issue to our grooming board as we've agreed that adding a migration doc section about this would be beneficial. |
The 3 solutions proposed didn't worked for me, but I was able to fix it by importing the adapter without using in next.js.
|
@fcpauldiaz Which import type {} from '@mui/x-date-pickers/AdapterDateFnsV3'; Does that help? |
this fixed the issue! thanks @LukasTy |
@andylacko: How did we do? Your experience with our support team matters to us. If you have a moment, please share your thoughts in this short Support Satisfaction survey. |
Steps to reproduce
Link to live example: this doesn't need repro, it is bad implementation of typescript
Steps:
DesktopDatePickerProps<Date>
Current behavior
doesn't accept Date or any type except never
Expected behavior
To accept javascript Date class as type
Context
typescript
Your environment
Search keywords: Type 'Date' does not satisfy the constraint 'never'
The text was updated successfully, but these errors were encountered: