Skip to content
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

[pickers] Replace the TDate generic with PickerValidDate in every type / interface #14796

Closed
flaviendelangle opened this issue Oct 1, 2024 · 1 comment · Fixed by #15001
Closed
Labels
breaking change component: pickers This is the name of the generic UI component, not the React module! typescript

Comments

@flaviendelangle
Copy link
Member

flaviendelangle commented Oct 1, 2024

Part of #13188

Small history

  • When we migrated the project from @mui/lab, after some cleaning we ended up with two generics:

    • TInputDate: the format supported by props.value which was the format parseable by the lib (usually something like Date | Dayjs | string | undefined)
    • TDate: the format of the date library (something like Dayjs)

    See [pickers] Rework TDate, TInputDate, TValue and TInputValue generics #4617 for the full context

  • In version 6.0.0, we dropped the support for unparsed dates

    People now have to pass value={dayjs('2022-04-17')}, formats like value="2022-04-17" no longer work.

    See [pickers] Do not support unparsed date formats anymore #6170 for the full context

  • In version 7.0.0, we created a new type PickerValidDate that each adapter enriches with its date format.
    The interfaces in the application can now limit the valid values of TDate to be TDate extends PickerValidDate.

    So the typing now looks something like this:

    interface DatePickerProps<TDate extends PickerValidDate> {
      value: TDate | null;
    }
    
    function DatePicker<TDate extends PickerValidDate>(props: DatePickerProps<TDate>) { ... }

Proposal

In a real application you have only one adapter so only one value added to PickerValidDate, which means we can remove the TDate generic and have the following:

interface DatePickerProps {
  value: PickerValidDate | null;
}

function DatePicker(props: DatePickerProps) { ... }

Search keywords:

Copy link

github-actions bot commented Nov 5, 2024

This issue has been closed. If you have a similar problem but not exactly the same, please open a new issue.
Now, if you have additional information related to this issue or things that could help future readers, feel free to leave a comment.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
breaking change component: pickers This is the name of the generic UI component, not the React module! typescript
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant