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

Possible to export the props for given components for typescript #1666

Closed
JeffBaumgardt opened this issue Apr 15, 2020 · 4 comments · Fixed by #1668
Closed

Possible to export the props for given components for typescript #1666

JeffBaumgardt opened this issue Apr 15, 2020 · 4 comments · Fixed by #1668

Comments

@JeffBaumgardt
Copy link

https://github.com/mui-org/material-ui-pickers/blob/2323a4b3e4e8479909ad5a9de4a671320506360f/lib/src/DateRangePicker/DateRangePicker.tsx#L30

Would it be possible to export the prop interfaces so that I can use them in typescript.

Reason:
I am writing a wrapper for the DateRangePicker. I'm just wrapping things that I need on top of it but the component is having a hard time dealing with props that are just transfered.

import {DateRangePicker} from '@material-ui/pickers'

type MyDate = {
  foo: string
  bar: string
}

const DateInput = (props) => {
  const {foo, bar, ...other} = props

  // something something foo / bar

  return <DateRangePicker {...other} />
}

I get a very ugly (and long) typescript error.

Type '{}' is missing the following properties from type 'Pick<DateRangePickerProps &
BasePickerProps<RangeInput, DateRange> & Pick<DateInputProps<RangeInput, DateRange>,
"color" | ... 292 more ... | "ignoreInvalidInputs"> & WithDateAdapterProps & DateValidationProps &
Pick<...>, "color" | ... 349 more ... | "disableAutoMonthSwitching">': onChange, focused, valuets(2739)

I believe if the interface was exported then I could import the props and use that to extend my type.

import {DateRangePicker, DateRangePickerProps} from '@material-ui/pickers'

type MyDate = DateRangePickerProps & {
  foo: string
  bar: string
}
...

For obvious reasons you would also have to extend those interfaces for the DesktopDateRangePicker and MobileDateRangePicker. Not including other components that may want to also export the types.

I ask because this is how @material-ui/core exports the types for each of the components.

@JeffBaumgardt
Copy link
Author

Ok, I found out that I can get rid of the typescript error by adding three apparently required fields.

  • value
  • onChange
  • focused (not sure why)

So the error is no longer a problem.

It would still be handy to have the props be exported for extending.

@oliviertassinari
Copy link
Member

@JeffBaumgardt This issue seems to resonate with #1631.

@dmtrKovalenko
Copy link
Member

@JeffBaumgardt please provide your case. I cannot reproduce an error with focused prop

@JeffBaumgardt
Copy link
Author

I'm not sure why the focued was required. I tried several times yesterday and it was erroring out if I was missing, value, onChange and focused. Today, however focused is no longer needed. I'm unsure why. Oh well.

Thanks for the types on the export. That will help 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants