[pickers] Simplify the typing of the codebase #14823
Labels
component: pickers
This is the name of the generic UI component, not the React module!
RFC
Request For Comments
typescript
Proposals to reduce the generic hell
0. Current state ✔️
Here is what an interface in the
@mui/x-date-pickers
package can currently look like:The properties of this interface were chosen to keep it simple and use every generic, not to represent any realistic usage.
1. Remove
TDate
generic in favor ofPickerValidDate
(v8) ✔️See #14796 for more context
Here is what the
0.
example would look like:2. Infer the
TSection
generic fromTValue
(v8) ✔️TSection
can be infered fromTValue
It equals
FieldSection
on non range andFieldSection & { rangePosition: 'start' | 'end' }
on rangeWe can remove it and infer it from
TValue
Here is what the
1.
example would look like (I also added anextend
toTValue
to make it safer):3. Add a
TManager
generic for interfaces that uses the new value manager (v8)See #14496 (comment) for full context
Some interfaces rely a lot on the following generics:
TSection
(or nothing if 2. is applied)TError
TInternalProps
If we introduce the notion of value manager as described in the link above, we can pass the manager as a generic to replace the 4 generic listed above:
The gain in generic is massive, but accessing those properties is more verbose (
PickerManagerProperties<TManager>['enableAccessibleFieldDOMStructure']
instead ofTEnableAccessibleFieldDOMStructure
).I think this is a massive win for interfaces that are widely used across the codebase (the interface itself can be slightly more verbose if it has several properties that uses the generic, but each usage of the interface is a lot lighter).
Side note, the property is named
fieldInternalProps
because value manager can also be introduced at the picker level in the future, so everything strictly related to the field has been named accordingly.4. Remove the
TEnableAccessibleFieldDOMStructure
generic (on v9)That one is pretty obvious, but once we drop the legacy DOM structure, this generic an be removed:
Here is what the
2.
example would look like:Examples
Search keywords:
The text was updated successfully, but these errors were encountered: