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.

Missing prop validation in React.FunctionComponent

See original GitHub issue

Tell us about your environment

  • ESLint Version: v6.0.1
  • Node Version: v10.16.0
  • npm Version: v6.9.0

Configuration

module.exports = {
  parser: '@typescript-eslint/parser',
  parserOptions: {
    project: './tsconfig.json',
  },
  plugins: ['@typescript-eslint'],
  extends: [
    'plugin:react/recommended',
    'plugin:@typescript-eslint/recommended',
  ],
}

What did you do? Please include the actual source code causing the issue, as well as the command that you used to run ESLint.

import * as React from 'react';
interface PersonProps {
    username: string;
}
const Person: React.FunctionComponent<PersonProps> = (props): React.ReactElement => (
    <div>{props.username}</div>
);
npx eslint src --ext .tsx

What did you expect to happen? eslint show no errors, because type definition actually present in generic type React.FunctionComponent<PersonProps>

What actually happened? Please include the actual, raw output from ESLint.

error    'username' is missing in props validation       react/prop-types

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:150
  • Comments:79 (29 by maintainers)

github_iconTop GitHub Comments

119reactions
shirly-chen-awxcommented, Aug 17, 2020
"overrides": [
        {
            "files": ["**/*.tsx"],
            "rules": {
                "react/prop-types": "off"
            }
        }
    ]

Support or ignore prop-types in mixed JS/TypeScript projects

96reactions
skubecommented, Sep 24, 2019

Adding : PersonProps (somewhat redundantly) seems to work…

const Person: React.FunctionComponent<PersonProps> = (props: PersonProps): React.ReactElement => (
    <div>{props.username}</div>
);
Read more comments on GitHub >

github_iconTop Results From Across the Web

Missing prop validation in React.FunctionComponent #2353
I have a functional component. With a typescript props interface. When I access a property off of the prop. I get <property> is...
Read more >
Props in functional component are missing in props validation
Eslint throwing eslint(react/prop-types) error despite already declared propTypes. I'm using eslint-plugin-react.
Read more >
How to validate React props using PropTypes - LogRocket Blog
Learn how to validate props with React PropTypes, React's internal mechanism for adding type checking to component props.
Read more >
is missing in props validation(react/prop-types) - You.com
You need to set the static property 'propTypes' on the component to satisfy this lint error. Here is some info about React's PropTypes:...
Read more >
ReactJS - Props Validation - Tutorialspoint
ReactJS - Props Validation, Properties validation is a useful way to force the correct usage of the components. This will help during development...
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