[DatePicker][TimePicker] Fix lab theme augmentation #30154
Closed
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Hi there,
While migrating a few older projects to V5, we ran into a Typescript issue where
@mui/lab
'sthemeAugmentation
for some of the Picker components was misconfigured. Existing issue from someone else: #29907The issue appears as a build error like
Property 'MuiDatePicker' does not exist on type 'ComponentsOverrides'. ts(2339)
orProperty 'MuiPickerStaticWrapper' does not exist on type 'ComponentsVariants'. ts(2339)
There are actually two separate but similar issues:
src/themeAugmentation/components.d.ts
, the MuiDatePicker and MuiDateTimePicker declaredstylesOverrides: ComponentsOverrides['MuiDatePicker']
. However, ComponentsOverrides does not have a key for those components because those Pickers are not style-able. From my digging, they do not expose aclasses
prop or have anyxxxClassMap
type available so I believe they actually don't have anystyleOverrides
available. My fix here was to remove thestyleOverrides
key in this type, similar to what is done with the Stack component heresrc/themeAugmentation/props.d.ts
,MuiPickerStaticWrapper
hadn't been added to the ComponentsPropsList types, so the use of that key in the themeAugmentation/components.d.ts file was invalid. Adding it to the list seemed like what was missing.There have been 2 PRs (#29517, #29517) over the past month that have touched/attempted to fix this exact code, so it may be worth a deeper look by maintainers.
Actual errors
```sh ../../node_modules/@mui/lab/themeAugmentation/components.d.ts:21:42 - error TS2339: Property 'MuiDatePicker' does not exist on type 'ComponentsOverrides'.21 styleOverrides?: ComponentsOverrides['MuiDatePicker'];
~~~~~~~~~~~~~~~
../../node_modules/@mui/lab/themeAugmentation/components.d.ts:31:42 - error TS2339: Property 'MuiDateTimePicker' does not exist on type 'ComponentsOverrides'.
31 styleOverrides?: ComponentsOverrides['MuiDateTimePicker'];
~~~~~~~~~~~~~~~~~~~
../../node_modules/@mui/lab/themeAugmentation/components.d.ts:110:36 - error TS2339: Property 'MuiPickerStaticWrapper' does not exist on type 'ComponentsProps'.
110 defaultProps?: ComponentsProps['MuiPickerStaticWrapper'];