Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Property does not exist on type 'IntrinsicAttributes & IntrinsicClassAttributes<DatePicker> & Readonly<{ children?: ReactNode; }> ...'

I'm trying to use React with TypeScript and Material-UI's components. Unfortunately, I'm getting the errors like this:

Property 'openToYearSelection' does not exist on type 'IntrinsicAttributes & IntrinsicClassAttributes & Readonly<{ children?: ReactNode; }> ...'.

import * as React from 'react';
import DatePicker from 'material-ui/DatePicker';

interface IState {
  birthday: any,
}

export default class SampleForm extends React.Component<IProps, IState> {
  constructor(props: any) {
    super(props);

    const { record = {} } = this.props;

    this.state = {
      birthday: record.birthday || null,
    };
  }

  public birthdayPicker() {
    const { birthday } = this.state;

    return (
      <DatePicker
        defaultDate={birthday}
        hintText="Birthday"
        openToYearSelection={true}
      />
    );
  }

  public render() {
    return (
      <form style={styles.root}>
        {this.header()}
        {this.firstName()}
        {this.lastName()}
        {this.birthdayPicker()}
        {this.phoneNumber()}
        {this.actionButtons()}
      </form>
    )
  }
}

What's the right way to use Material-UI with TypeScript and React?

like image 275
digitalCoffee Avatar asked Oct 28 '22 13:10

digitalCoffee


1 Answers

I've resolved this problem by adding missing properties to namespaces in node_modules/@types/material-ui/index.d.ts file. It worked for me. I don't think that it's a good solution and I'm wondering if there're some better approaches.

namespace DatePicker {
    export interface DatePickerProps {
        defaultDate?: Date;
        disableYearSelection?: boolean;
        ..
like image 157
digitalCoffee Avatar answered Nov 09 '22 16:11

digitalCoffee