Material-ui-pickers: Typescript error with KeyboardDatePicker

Created on 18 Sep 2019  路  6Comments  路  Source: mui-org/material-ui-pickers

!https://imgflip.com/i/3av1tk

Environment

| Tech | Version |
| -------------------- | ------- |
| @material-ui/pickers | 3.2.6 |
| material-ui | 4.4.2 |
| React | 16.8.6 |
| Browser | Brave(Chrome)|
| Peer library | | |

Steps to reproduce

Use KeyboardDatePicker component, with props from demo for instance in a TSX file (using typescript then)

Expected behavior

No compilation error

Actual behavior

Get this compilation error:
Error:(41, 10) TS2740: Type '{ clearable: true; fullWidth: true; format: string; views: DatePickerView[]; label: Element; value: any; inputVariant: "outlined" | "standard" | "filled"; onChange: (date: Moment) => void; ... 12 more ...; disabled: boolean; }' is missing the following properties from type 'Pick': style, defaultValue, className, innerRef, and 3 more.

Example

Here are the props I use :

<KeyboardDatePicker
          clearable
          fullWidth
          format={format.printFormat}
          views={format.view}
          label={id === undefined ? null : <FormattedMessage id={id} />}
          value={formattedValue}
          inputVariant={variant}
          onChange={date => onChange(date)}
          onFocus={() => setIsFocused(true)}
          onBlur={() => setIsFocused(false)}
          InputAdornmentProps={{
            position: 'start',
          }}
          required={required}
          invalidLabel=""
          cancelLabel={<FormattedMessage id="form.cancel" />}
          clearLabel={<FormattedMessage id="form.raz" />}
          minDate={minDate}
          error={!meta.valid && (meta.touched || submitted)}
          InputLabelProps={{
            shrink: (formattedValue !== null || isFocused),
            className: (formattedValue === null && !isFocused) ? classes.dateLabelBase : null,
          }}
          InputProps={{
            endAdornment: (helperText !== undefined
              ? (
                <InputAdornment position="end">
                  <IconButton
                    onClick={() => setShowHelp(!showHelp)}
                    className={classes.formIcon}
                    tabIndex={-1}
                  >
                    {showHelp ? <Help /> : <HelpOutline />}
                  </IconButton>
                </InputAdornment>
              ) : null
            ),
          }}
          helperText={!meta.valid && (meta.touched || submitted) ? <FormattedMessage id={meta.error} {...{ style: { color: 'red' } }} /> : null}
          disabled={disabled}
        />

Most helpful comment

The props that are required for me are: onBlur, onFocus, className, ref, innerRef, rows, rowsMax, variant, and style. Providing those (even with useless values,) allows me to compile.

All 6 comments

Environment

@material-ui/pickers | 3.2.5
material-ui | 4.4.0
React | 16.8.6
Browser | Chrome

Steps to reproduce

Use KeyboardDatePicker component and use 'yarn' to install the dependencies.
I don't meet a such error with 'npm install'.

Actual behavior

Type '{ autoOk: true; variant: "inline"; format: string | undefined; emptyLabel: string; inputVariant: "outlined"; label: string | undefined; views: ("month" | "year" | "date")[]; value: Moment | null; ... 4
more ...; onOpen: () => void | undefined; }' is missing the following properties from type 'Pick<KeyboardDateInputProps, "name" | "label" | "onClick" | "children" | "ref" | "select" | "style" | "title" | "mask" | "key" | "className" | "color" | "id" | "lang" | "type" | ... 269 more ... | "rifmFormatter">': ref, style, className, rows, and 2 more. 

Example

<KeyboardDatePicker autoOk variant="inline" format={format} emptyLabel={emptyLabel} inputVariant="outlined" label={noFloatLabel ? '' : label} views={views} value={fieldValue ? moment(fieldValue, format) : null} InputAdornmentProps={{ position: 'end' }} onChange={(date) => date && setFieldValue && setFieldValue(name, date.format(format))} onBlur={onBlur} onFocus={() => onClick && onClick(name)} onOpen={() => onClick && onClick(name)}

Indeed, I use yarn.
Thanks for the code formatting btw.

I digged a little bit by taking a look at the type files.
the interface KeyboardDateInputProps has also an error :
TS2430: Interface聽'KeyboardDateInputProps'聽incorrectly聽extends聽interface聽'Pick<TextFieldProps,聽"fullWidth"聽|聽"defaultValue"聽|聽"manifest"聽|聽"defaultChecked"聽|聽"suppressContentEditableWarning"聽|聽"suppressHydrationWarning"聽|聽"accessKey"聽|聽"className"聽|聽...聽266聽more聽...聽|聽"type">'. 聽聽Property聽'InputProps'聽is聽optional聽in聽type聽'KeyboardDateInputProps'聽but聽required聽in聽type聽'Pick<TextFieldProps,聽"fullWidth"聽|聽"defaultValue"聽|聽"manifest"聽|聽"defaultChecked"聽|聽"suppressContentEditableWarning"聽|聽"suppressHydrationWarning"聽|聽"accessKey"聽|聽"className"聽|聽...聽266聽more聽...聽|聽"type">'.

Could it be related to TextFieldProps from material UI ?

The props that are required for me are: onBlur, onFocus, className, ref, innerRef, rows, rowsMax, variant, and style. Providing those (even with useless values,) allows me to compile.

I have the same problem with yarn and material-ui/core.
Adding the properties that @ikesau mentioned and inputRef lets me render the DatePicker.

I updated to the new version of typescript and problem was solved. The issue was in old version of typescript in Pick, it changes optional properties to required.

Indeed a problem is in typescript version 馃う鈥嶁檪
We added this custom Omit because accidentially updated to the new ts version which already have Omit included. So I suppose we need a new minor release requiring update to the minor typescript version. :(

Was this page helpful?
0 / 5 - 0 ratings

Related issues

callmeberzerker picture callmeberzerker  路  3Comments

Lysander picture Lysander  路  3Comments

basselAhmed picture basselAhmed  路  3Comments

StevenRasmussen picture StevenRasmussen  路  3Comments

danmce picture danmce  路  3Comments