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] DateBuilderReturnType provides wrong type with no arg #13239

Closed
alexey-kozlenkov opened this issue May 24, 2024 · 3 comments · Fixed by #13244
Closed

[pickers] DateBuilderReturnType provides wrong type with no arg #13239

alexey-kozlenkov opened this issue May 24, 2024 · 3 comments · Fixed by #13244
Labels
bug 🐛 Something doesn't work component: pickers This is the name of the generic UI component, not the React module! typescript

Comments

@alexey-kozlenkov
Copy link
Contributor

alexey-kozlenkov commented May 24, 2024

Steps to reproduce

Add this test case to test/utils/pickers/describeGregorianAdapter/testCalculations.ts:

  describe('Method: date', () => {
    //...

    it('should work without args', () => {
      const date = adapter.date().valueOf()

      expect(Math.abs(date - Date.now())).to.be.lessThan(5)
    })
  })
image

Current behavior

adapter.date() return type is Date | null

Expected behavior

adapter.date() return type should be just Date - same if undefined passed explicitly adapter.date(undefined)

Context

This might be happening because of Distributive conditional types and has an easy fix in types packages/x-date-pickers/src/models/adapters.ts:

-export type DateBuilderReturnType<T extends string | null | undefined, TDate> = T extends null
+export type DateBuilderReturnType<T extends string | null | undefined, TDate> = [T] extends [null]
   ? null
   : TDate;

Your environment

npx @mui/envinfo
  Don't forget to mention which browser you used.
  Output from `npx @mui/envinfo` goes here.

Search keywords: DateBuilderReturnType mui-x-date-pickers

@alexey-kozlenkov alexey-kozlenkov added the status: waiting for maintainer These issues haven't been looked at yet by a maintainer label May 24, 2024
@zannager zannager added the component: pickers This is the name of the generic UI component, not the React module! label May 24, 2024
@michelengelen
Copy link
Member

Hey @alexey-kozlenkov
Looks like a good fix.
Would you mind opening a PR for this?

@michelengelen michelengelen added bug 🐛 Something doesn't work typescript status: waiting for author Issue with insufficient information and removed status: waiting for maintainer These issues haven't been looked at yet by a maintainer labels May 24, 2024
@alexey-kozlenkov
Copy link
Contributor Author

@michelengelen sure, let me try to do that

@github-actions github-actions bot added status: waiting for maintainer These issues haven't been looked at yet by a maintainer and removed status: waiting for author Issue with insufficient information labels May 24, 2024
@michelengelen michelengelen removed the status: waiting for maintainer These issues haven't been looked at yet by a maintainer label May 27, 2024
Copy link

⚠️ 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.

@alexey-kozlenkov: How did we do? Your experience with our support team matters to us. If you have a moment, please share your thoughts in this short Support Satisfaction survey.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug 🐛 Something doesn't work 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.

3 participants