3

I cannot figure out why this import or any other does not work:

    import * as React from 'react';
    import TextField from '@material-ui/core/TextField';
    import * as PropTypes from 'prop-types';
    import { withStyles } from '@material-ui/core/styles';
    //import { PropTypes } from '@material-ui/core';

    interface IProps {
        value: string;
        onChange?: PropTypes.func;
    }

    const textField = (props: IProps) => {
        return (
            <div>HI</div>
        );
    };

    export default textField;

The error I receive is:

ts-app/node_modules/@types/prop-types/index"' has no exported member 'func'

I am looking in this file and it seems to clearly have such a member:

export const func: Requireable<(...args: any[]) => any>;

perhaps one day I will understand React and how these dependencies work, Thanks!

Shorn
  • 19,077
  • 15
  • 90
  • 168
Numnumberry
  • 415
  • 4
  • 16

1 Answers1

2

PropTypes.func is a value (intended to be used in a propTypes property of a stateless function component or static property of a component class), but you are trying to use it as a type. Instead, you could manually write the underlying type:

onChange?: (...args: any[]) => any;

or hopefully a more specific one appropriate for your application.

I filed an issue for the poor error message.

Matt McCutchen
  • 28,856
  • 2
  • 68
  • 75