diff --git a/docs/data/date-pickers/base-concepts/base-concepts.md b/docs/data/date-pickers/base-concepts/base-concepts.md index 82590c92d376a..746fffbba34d2 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'; ``` +:::success +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 0000000000000..dd2a0f637e9ba 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 0000000000000..d216b32928485 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 16e67bd94f2cd..916d29c2fa8fd 100644 --- a/packages/x-date-pickers/src/models/pickers.ts +++ b/packages/x-date-pickers/src/models/pickers.ts @@ -11,6 +11,6 @@ export interface PickerChangeHandlerContext { export interface PickerValidDateLookup {} -export type PickerValidDate = keyof PickerValidDateLookup extends never +export type PickerValidDate = keyof PickerValidDateLookup extends string ? any : PickerValidDateLookup[keyof PickerValidDateLookup];