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

crashes on stateless react class #2179

Closed
spudly opened this issue Feb 27, 2019 · 8 comments · Fixed by #2232
Closed

crashes on stateless react class #2179

spudly opened this issue Feb 27, 2019 · 8 comments · Fixed by #2232

Comments

@spudly
Copy link

spudly commented Feb 27, 2019

I'm getting this error:

TypeError: Cannot read property 'type' of undefined
    at resolveSuperParameterPropsType (node_modules/eslint-plugin-react/lib/util/propTypes.js:615:20)
    at Object.ClassDeclaration (node_modules/eslint-plugin-react/lib/util/propTypes.js:651:39)
    at updatedRuleInstructions.(anonymous function) (node_modules/eslint-plugin-react/lib/util/Components.js:748:43)
    at listeners.(anonymous function).forEach.listener (node_modules/eslint/lib/util/safe-emitter.js:45:58)
    at Array.forEach (<anonymous>)
    at Object.emit (node_modules/eslint/lib/util/safe-emitter.js:45:38)
    at NodeEventGenerator.applySelector (node_modules/eslint/lib/util/node-event-generator.js:251:26)
    at NodeEventGenerator.applySelectors (node_modules/eslint/lib/util/node-event-generator.js:280:22)
    at NodeEventGenerator.enterNode (node_modules/eslint/lib/util/node-event-generator.js:294:14)
    at CodePathAnalyzer.enterNode (node_modules/eslint/lib/code-path-analysis/code-path-analyzer.js:632:23)

It appears to be caused by a react class that has no state. It crashes for this code:

class MyClass extends React.Component<Props> {}

...but does not crash if you add a state annotation:

class MyClass extends React.Component<Props, State> {}
@ljharb
Copy link
Member

ljharb commented Feb 27, 2019

Is this TS or Flow?

@spudly
Copy link
Author

spudly commented Feb 27, 2019 via email

@ljharb ljharb added the flow label Feb 27, 2019
@ahutchings
Copy link

I'm seeing this issue with TypeScript as well. Adding an empty State interface works around the error.

@ljharb
Copy link
Member

ljharb commented Apr 2, 2019

A PR to fix both would be great.

@jedwards1211
Copy link
Contributor

jedwards1211 commented Apr 10, 2019

The number of crashes fixed in the changelog recently really illustrates the pitfalls of managing a complex codebase like this without using TypeScript or Flow

@ljharb
Copy link
Member

ljharb commented Apr 11, 2019

I don’t agree; it’s just the legacy of not being rigorous about defensive programming in this repo. That’s no longer the case.

@jedwards1211
Copy link
Contributor

jedwards1211 commented Apr 11, 2019

Defensive programming is of course always good, but what I'm saying is that Flow (and I assume TypeScript?) would have caught this potential NPE before it was ever published (and probably many other type errors in this codebase). I doubt there's any programmer who's as good at remembering to include null checks as Flow is at requiring them.

@ljharb
Copy link
Member

ljharb commented Apr 11, 2019

Maybe so, but that relies on the parser types always being correct too. Either way, writing not-javascript in this repo isn’t on the horizon.

ljharb pushed a commit to jedwards1211/eslint-plugin-react that referenced this issue Apr 12, 2019
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.

4 participants