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

Intersection Flow Type error #1468

Closed
dawidvdh opened this issue Oct 8, 2017 · 7 comments
Closed

Intersection Flow Type error #1468

dawidvdh opened this issue Oct 8, 2017 · 7 comments

Comments

@dawidvdh
Copy link
Contributor

dawidvdh commented Oct 8, 2017

Receiving the following error:

Cannot read property 'properties' of undefined
TypeError: Cannot read property 'properties' of undefined
    at annotation.types.reduce (/Users/proj/node_modules/eslint-plugin-react/lib/rules/default-props-match-prop-types.js:180:44)
    at Array.reduce (<anonymous>)
    at getPropertiesFromIntersectionTypeAnnotationNode (/Users/proj/node_modules/eslint-plugin-react/lib/rules/default-props-match-prop-types.js:173:31)
    at getPropTypesFromTypeAnnotation (/Users/proj/node_modules/eslint-plugin-react/lib/rules/default-props-match-prop-types.js:197:26)
    at Object.handleStatelessComponent (/Users/proj/node_modules/eslint-plugin-react/lib/rules/default-props-match-prop-types.js:331:42)
    at updatedRuleInstructions.(anonymous function) (/Users/proj/node_modules/eslint-plugin-react/lib/util/Components.js:666:75)
    at listeners.(anonymous function).forEach.listener (/Users/proj/node_modules/eslint/lib/util/safe-emitter.js:47:58)
    at Array.forEach (<anonymous>)
    at Object.emit (/Users/proj/node_modules/eslint/lib/util/safe-emitter.js:47:38)
    at NodeEventGenerator.applySelector (/Users/proj/node_modules/eslint/lib/util/node-event-generator.js:251:26)

When attempting to use intersection flow type like so:

import type { FieldProps } from "redux-form"

type Props = {
  label: string,
  type: string,
  options: Array<SelectOption>
} & FieldProps

I looked through previous issues and PR's and noticed similar issues however I am not sure if this has been resolved or not or if I am not doing this correctly.

Also I am using version 7.4.0 of this plugin.

@leethree
Copy link

leethree commented Oct 9, 2017

I'm seeing the same issue since I enabled react/default-props-match-prop-types rule. The error goes away when I disable the rule.

@ryami333
Copy link

ryami333 commented Oct 15, 2017

Hope this helps, these are my steps to reproduce:
This works:

// @flow

import React from 'react';
import type { ElementProps } from 'react';
import './button.scss';

type FooProps = ElementProps<'div'>;

function Foo(props: FooProps) {
    return (
        <div {...props} />
    );
}

export default Foo;

This errors (introduced additional prop 'bar'):

// @flow

import React from 'react';
import type { ElementProps } from 'react';
import './button.scss';

type FooProps = ElementProps<'div'> & {
	bar: string,
};

function Foo(props: FooProps) {
    return (
        <div {...props} />
    );
}

Foo.defaultProps = {
	bar: 'hello world',
}

export default Foo;

@ryami333
Copy link

Could be wrong, but seems related to this issue: #1413

@beaugunderson
Copy link

beaugunderson commented Oct 17, 2017

we're also hitting this; with the additional issue that the reference intersection type is made available from our .flowconfig's [libs] section as a declared type vs. being an imported one

update: I've imported the type and also changed whether the intersection is before or after the other defined props (e.g. Type & {} vs. {} & Type; those changes made no difference

we get the same error as the OP in default-props-match-prop-types.js; we're using [email protected]

@Morglod
Copy link

Morglod commented Nov 2, 2017

// @flow

type Opts = { name: string } & { kek: Function }

// eslint crash
function foo({ name }: Opts) {}

// no error
function foo(opts: Opts) {
    const { name } = opts;
}

eslint-react-plugin crashes when see union type destructuring

@justinanastos
Copy link
Contributor

justinanastos commented Nov 22, 2017

I created an MR with a failing test case and hopefully a resolution to this.

#1563

@ljharb
Copy link
Member

ljharb commented Nov 22, 2017

Fixed in #1563

@ljharb ljharb closed this as completed Nov 22, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

No branches or pull requests

7 participants