diff --git a/docs/data/date-pickers/base-concepts/base-concepts.md b/docs/data/date-pickers/base-concepts/base-concepts.md index 82590c92d376..bdae427685bc 100644 --- a/docs/data/date-pickers/base-concepts/base-concepts.md +++ b/docs/data/date-pickers/base-concepts/base-concepts.md @@ -185,15 +185,28 @@ To correctly type all the props that are date-related, the adapters override a g to allow the usage of their own date format. This allows TypeScript to throw an error if you try to pass `value={new Date()}` to a component using `AdapterDayjs` for instance. -If you run into TypeScript errors such as `DesktopDatePickerProps error Type 'Date' does not satisfy the constraint 'never'`, -it is probably because you are not importing the adapter in the same TypeScript project as the rest of your codebase. -You can fix it by manually importing the adapter in some file of your project as follows: +If you are not sure your adapter is set up correctly to infer the type of date-related props, you can import the `PickerValidDate` type and check its current value. + +If its equal to the format used by your date library, then you don't have to do anything: + +PickerValidDate correctly configured + +If it's equal to `any`, you can fix it by manually importing the adapter in some file of your project as show below: + +PickerValidDate not correctly configured ```ts // Replace `AdapterDayjs` with the adapter you are using. import type {} from '@mui/x-date-pickers/AdapterDayjs'; ``` +:::info +Before version 7.19.0, TypeScript was throwing an error such as `DesktopDatePickerProps error Type 'Date' does not satisfy the constraint 'never'` +when you were not importing the adapter in the same TypeScript project as the rest of your codebase. + +The fix described above should also solve the problem. +::: + ## Testing caveats ### Responsive components diff --git a/docs/public/static/x/date-pickers/picker-valid-date-configured.png b/docs/public/static/x/date-pickers/picker-valid-date-configured.png new file mode 100644 index 000000000000..dd2a0f637e9b Binary files /dev/null and b/docs/public/static/x/date-pickers/picker-valid-date-configured.png differ diff --git a/docs/public/static/x/date-pickers/picker-valid-date-not-configured.png b/docs/public/static/x/date-pickers/picker-valid-date-not-configured.png new file mode 100644 index 000000000000..d216b3292848 Binary files /dev/null and b/docs/public/static/x/date-pickers/picker-valid-date-not-configured.png differ diff --git a/packages/x-date-pickers/src/models/pickers.ts b/packages/x-date-pickers/src/models/pickers.ts index db341d045e20..d84c87dbbd59 100644 --- a/packages/x-date-pickers/src/models/pickers.ts +++ b/packages/x-date-pickers/src/models/pickers.ts @@ -11,4 +11,6 @@ export interface PickerChangeHandlerContext { export interface PickerValidDateLookup {} -export type PickerValidDate = PickerValidDateLookup[keyof PickerValidDateLookup]; +export type PickerValidDate = keyof PickerValidDateLookup extends number + ? any + : PickerValidDateLookup[keyof PickerValidDateLookup];