facebook / react

The library for web and native user interfaces.
https://react.dev
MIT License
229.11k stars 46.87k forks source link

[React 19] Eslint React JSDoc support #28935

Closed eduardocque closed 6 months ago

eduardocque commented 6 months ago

Summary

based on react 19 documentation prop-types is gone, so for JS users the only way to manage it is using JSDoc, can be possible to support jsdoc prop-type validation in eslint-plugin-react ?

Example

/**
 * @param {{
 *   content?: string,
 *   requiredParameter: string // required parameter if not can be with "?"
 * }} props
 * @returns {React.ReactElement}
 */
const ChildElement = props => {
  const { content = '' } = props;

  return <div>{content}</div>;
};

/** @returns {React.ReactElement} */
const ParentElement = () => {
  return <ChildElement content="Hello World" wrongParameter="test" />;
};

in this example

the intention of this request if to give some ways in javascrit to work without involve typescript to maange types and props

kassens commented 6 months ago

Unfortunately, type checking is a very complex task and out of the capabilities that a eslint plugin can provide (you need to look across files to start, which as far as I know isn't supported by ESLint).

For static type checking TypeScript (and Flow) are the supported ways.