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 trialAdam Beer
11,314 Points[ts] 'types' can only be used in a .ts file.
Hi. I have a problem. Screenshot from my porject.
If I drag the mouse, on to the opening curly bracket, after static propTypes:, then this is the error code -> [ts] 'types' can only be used in a .ts file.
My project is working so this is an interesting mistake for me. How to fix it? Anybody has an idea what is the wrong?
Thanks for the help!
1 Answer
Seokhyun Wie
Full Stack JavaScript Techdegree Graduate 21,606 PointsSeems quite late to answer Adams Q, but for sb who has the same issue like me and the past Adam, This is with function declaration:
function Foo() {
this.PropTypes = somePropTypes; // bad
return <div></div>;
}
Foo.PropTypes = somePropTypes; // good
This one is with Component:
class Foo extends React.Component {
static PropTypes = somePropTypes;
}
These example are from stackoverflow, link is here.
Most importantly, using PropTypes directly from React is deprecated from v16 React, as well as the createClass. You can check your console, but for you information, you can find npm package 'prop-types' here and it's easy to apply so I wouldn't describe everything here. Happy Coding folks!
Adam Beer
11,314 PointsAdam Beer
11,314 PointsIf I rewrite : on to = after the static propTypes it working fine, and doesn't give an error message. But I'm not sure how this is the best way.