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

TypeError: Cannot read property 'type' of undefined on Flow type #2605

Closed
literat opened this issue Mar 25, 2020 · 1 comment · Fixed by #2606
Closed

TypeError: Cannot read property 'type' of undefined on Flow type #2605

literat opened this issue Mar 25, 2020 · 1 comment · Fixed by #2606

Comments

@literat
Copy link

literat commented Mar 25, 2020

Hi,

since version 7.17.0 of eslint-plugin-react linting failed with:

TypeError: Cannot read property 'type' of undefined
Occurred while linting /Users/literat/Work/lmc/fp-admin/src/components/UI/Forms/Hidden.js:15
    at getKeyValue (/Users/literat/Work/lmc/fp-admin/node_modules/eslint-plugin-react/lib/util/ast.js:172:14)
    at /Users/literat/Work/lmc/fp-admin/node_modules/eslint-plugin-react/lib/util/propTypes.js:284:19
    at iterateProperties (/Users/literat/Work/lmc/fp-admin/node_modules/eslint-plugin-react/lib/util/propTypes.js:45:9)
    at declarePropTypesForObjectTypeAnnotation (/Users/literat/Work/lmc/fp-admin/node_modules/eslint-plugin-react/lib/util/propTypes.js:271:5)
    at markPropTypesAsDeclared (/Users/literat/Work/lmc/fp-admin/node_modules/eslint-plugin-react/lib/util/propTypes.js:474:33)
    at Object.markAnnotatedFunctionArgumentsAsDeclared (/Users/literat/Work/lmc/fp-admin/node_modules/eslint-plugin-react/lib/util/propTypes.js:620:7)
    at updatedRuleInstructions.<computed> (/Users/literat/Work/lmc/fp-admin/node_modules/eslint-plugin-react/lib/util/Components.js:883:43)
    at /Users/literat/Work/lmc/fp-admin/node_modules/eslint/lib/util/safe-emitter.js:45:58
    at Array.forEach (<anonymous>)
    at Object.emit (/Users/literat/Work/lmc/fp-admin/node_modules/eslint/lib/util/safe-emitter.js:45:38)

Failed component is this one:

// @flow
import React, { type Element } from 'react';

type THiddenProps = {|
  id?: string,
  name?: string,
  defaultValue?: string,
  ...any,
|};

const defaultProps = {
  defaultValue: '',
};

const Hidden = ({
  id,
  name,
  defaultValue,
  rest,
}: THiddenProps): Element<'input'> => (
  <input
    type="hidden"
    id={id}
    name={name}
    defaultValue={defaultValue}
    className="form-control"
    {...rest}
  />
);

Hidden.defaultProps = defaultProps;

export default Hidden;

If I remove or comment out THiddenProps everything works fine:

// @flow
import React, { type Element } from 'react';

type THiddenProps = {|
  id?: string,
  name?: string,
  defaultValue?: string,
  ...any,
|};

const defaultProps = {
  defaultValue: '',
};

const Hidden = (
  { id, name, defaultValue, rest } /**: THiddenProps*/,
): Element<'input'> => (
  <input
    type="hidden"
    id={id}
    name={name}
    defaultValue={defaultValue}
    className="form-control"
    {...rest}
  />
);

Hidden.defaultProps = defaultProps;

export default Hidden;

Am I doing something wrong or is this a bug?

Thank you for your help.

@ljharb
Copy link
Member

ljharb commented Mar 25, 2020

Looks like a bug. a PR with a failing test case would be very helpful.

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

Successfully merging a pull request may close this issue.

2 participants