3

I know that there is ability to check JS code with TS compiler. And I know that TS compiler understand JSDoc comments (https://github.com/Microsoft/TypeScript/wiki/JSDoc-support-in-JavaScript).

I want to use TS compiler with my React project and I don't know how specify props definitions with JSDoc :(

I've tried

class PropertyDetails extends React.Component {
  static propTypes = {
    breadcrumbChange: PropTypes.func,
    folderId: PropTypes.string.isRequired
  }

  /**
   * @typedef {Object} Props
   * @property {function} breadcrumbChange
   * @property {string} folderId
   */

  /**
   * @constructor
   * @param {Props} props
   */
  constructor(props) {
    super(props);

but it doesn't work.

2
  • Simplest solution: Actually use TS and define an interface for Props and use constructor(props: Props) Commented Dec 6, 2017 at 15:59
  • It's not my decision to use JS and not TS :( Commented Dec 6, 2017 at 16:04

1 Answer 1

1

To make IntelliSense and type checking working you have to specify prop types for Component class since in typings it is described like generic object. So if you try something like this

/**
 * @typedef {Object} Props
 * @prop {Function} breadcrumbChange
 * @prop {string} folderId
 * @extends React.Component<Props>
 */
class PropertyDetails extends React.Component {
}

it should work

Sign up to request clarification or add additional context in comments.

1 Comment

narrator: it didn't

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.