Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

JavaScript React Basics (retired) Thinking in Components Loops and Lists in JSX

Brendan Whiting
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
Brendan Whiting
Front End Web Development Techdegree Graduate 84,735 Points

Some questions about React propTypes

Looking at this piece of code:

  propTypes: {
    title: React.PropTypes.string,
    initialPlayers: React.PropTypes.arrayOf(React.PropTypes.shape({
      id: React.PropTypes.number.isRequired,
      name: React.PropTypes.string.isRequired,
      score: React.PropTypes.number.isRequired
    })).isRequired  
  },

Is this about avoiding bugs from the developer or validating user input? Is this comparable to the Angular people bringing TypeScript into Angular 2?

2 Answers

Jeremy Castanza
Jeremy Castanza
12,081 Points

My take on this is that Javascript is trying to become a more mature language. Other programming languages typically include datatypes when defining variables. Vanilla Javascript doesn't really enforce datatypes or give you meaningful errors when issues related to datatype occur in your program.

akak
akak
29,445 Points

It's more like TypeScript. It's for developers to have indication what data component expects and other developers (or you from the future) should pass into it.