-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
'(react/prop-types): Missing in props validation' when props interface extends from another #2654
Comments
I also get this error for interface Foo {
x: number;
}
interface Bar extends Foo {
y: string;
}
const Baz = ({ x, y }: Bar) => (
<span>
{x}
{y}
</span>
); While yarn upgrade also upgraded |
This error actually occurs a second time in our code base after the upgrade: function useBar(): { x: number; y: string } {
return { x: 123, y: "" };
}
const Foo = () => {
const props = useBar();
return <span>{props.x}</span>; // 'x' is missing in props validation
}; Renaming |
So worked around all these changing all my extends. Now on the latest version now seems complains when the props are defined but the component returns interface Props {
value?: string;
}
// without the | null, all ok, with it, it is broken
function Test ({ value }: Props): React.ReactElement<Props> | null {
if (!value) {
return null;
}
return <div>{value}</div>;
} Additionally, this is also problematic (was working before most recent update to .3, same as above) - import { ComponentProps as Props } from './types';
function Test ({ className = '' }: Props): React.ReactElement<Props> {
return <div className={className}>something</div>;
} |
I'm also having this problem using type Props = {
title: string;
name?: string;
};
const Component: React.FC<Props> = ({title, name}) => (...) This will give me the error that the props validation is missing
|
I had the same problem. Turns out it didn't like me returning a ternary. 🤷♂️ |
@drodriguln, same thing for me 🤔 |
Also, in other cases, I also get the error described in this issue related to extended props. |
And it looks like the problem is already solved in the upstream: 4ee6f8e |
@goooseman that's included in v7.20.3. Have you tried that version? |
Yep, I've tried. And it was throwing the error, if Typescript interface has been used. |
@goooseman could you provide a reduced test case that's incorrect in the latest version? |
Using Example:
It'll complain about the prop from the extended interface |
The issue I was having was on 7.20.0. I tried to update to 7.20.3, latest version but made no difference for the problem I mentioned above. That is, of course, a typescript issue, maybe there needs to be a different issue made for that? |
For those who encounter this issue. |
Reason: Seems like if you have used the word "props" in your objects this error gets triggered PS: we tried downgrading to |
The upgrade from 7.20.0 -> 7.20.1 seems to be causing the issue for me. |
Yup. Downgrading back to 7.20.0 resolved this for me. |
…ript props interface extension and TSTypeAliasDeclaration Fixes jsx-eslint#2654. Fixes jsx-eslint#2719. Fixes jsx-eslint#2703.
…ript props interface extension and TSTypeAliasDeclaration Fixes jsx-eslint#2654. Fixes jsx-eslint#2719. Fixes jsx-eslint#2703.
…ript props interface extension and TSTypeAliasDeclaration Fixes jsx-eslint#2654. Fixes jsx-eslint#2719. Fixes jsx-eslint#2703.
do we know which version this will be released in? |
@damiangreen if you click on the commit that closed the PR, you'll see it's not released in anything yet. So, the answer to your question is "the next release". |
I just tested the version
this is the
and there are multiple components that |
@S-Amin thanks; could you file a new issue? |
@ljharb upgrading to the latest version |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
For me, upgrading eslint-plugin-react to the latest version 7.21.5 fixed this |
in |
@thayllachristine please file a new issue? |
This comment has been minimized.
This comment has been minimized.
We are facing the same issue. with |
@sambhav-gore please file a new issue? |
we have the same problem with version 7.22, I tried to downgrade and I had no results either. |
@zakur777 just like the last three comments; please file a new issue? |
This comment has been minimized.
This comment has been minimized.
@DamengRandom then please file a new issue? |
Hi @ljharb, Would you know how to fix this issue without disable the eslint rule? I really wish this error can be fixed: (FYI, I am using typescript and material-ui) |
Hi @ljharb, its really hard one for me now, but I use an alternative solution to resolve this issue: which is instead of using arrow function, we use normal function, something like this:
NOT use this:
However, I still want to typescript to fix this issue (at least if my codebase is using typescript, this rule does not require, which should only be available on es6, right?) Or would you mind to offer me some feedback? |
It seems there is no any fix to this problem. |
code snippet
.eslintrc
when running eslint , I got the following warning:
warning 'removeCollection' is missing in props validation react/prop-types
The text was updated successfully, but these errors were encountered: