question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

prop-types and es7.objectRestSpread

See original GitHub issue

I’m currently getting a lint warning saying that a prop is not defined with the following example:

import React from 'react';
import SharedPropTypes from './SharedPropTypes';

export default class A extends React.Component {
  render() {
    return (
      <span
        a={this.props.a}
        b={this.props.b}
        c={this.props.c}>
        {this.props.children}
      </span>
    );
  }
}

A.propTypes = {
  a: React.PropTypes.string,
  ...SharedPropTypes // eslint-disable-line object-shorthand
};

The propTypes are getting assigned utilizing the experimental Stage 1 feature from Babel es7.objectRestSpread.

I already have to disable one line as it is not yet supported in eslint as per eslint/eslint#2514.

I don’t know if this is a limiting issue due to eslint not supporting this ES7 feature yet or not.

Issue Analytics

  • State:closed
  • Created 8 years ago
  • Comments:9 (3 by maintainers)

github_iconTop GitHub Comments

2reactions
Coobahacommented, Aug 6, 2015

@mtscout6 this should work

A.propTypes = Object.assign({...SharedPropTypes}, {
  a: React.PropTypes.string,
});
0reactions
yannickcrcommented, Jan 11, 2016

I fixed a crash related to the spread operator (#389). Components propTypes validation is now ignored if propTypes are using the spread operator (since in this case we cannot determine what propTypes are defined or not).

Read more comments on GitHub >

github_iconTop Results From Across the Web

prop-types and es7.objectRestSpread · Issue #106 - GitHub
I'm currently getting a lint warning saying that a prop is not defined with the following example: import React from 'react'; ...
Read more >
Using ES7 static propTypes with React-Native - Stack Overflow
When I'm launching my project using React-Native default packager, I have this error: Unexpected token on this line: static propTypes = { ///...
Read more >
[Solved]-Using ES7 static propTypes with React-Native-React ...
Coding example for the question Using ES7 static propTypes with React-Native-React Native.
Read more >
Parse prop-types - johnlivingston.io - Snippet
An experiment with JavaScript AST (Abstract Syntax Tree) using acorn to parse prop-types.
Read more >
Typechecking With PropTypes - React
To run typechecking on the props for a component, you can assign the special propTypes property: import PropTypes from 'prop-types'; class Greeting extends ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found