Skip to content

Typescript false positive "missing in props validation" on interfaces #2719

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

Closed
abemedia opened this issue Jul 19, 2020 · 7 comments · Fixed by #2721
Closed

Typescript false positive "missing in props validation" on interfaces #2719

abemedia opened this issue Jul 19, 2020 · 7 comments · Fixed by #2721

Comments

@abemedia
Copy link

When creating a type with interface...extends the props from the type that is being extended are ignored.

The following for example throws 'style' is missing in props validation eslint(react/prop-types):

interface ThingProps extends React.HTMLAttributes<HTMLDivElement> {
  thing?: number
}

export const Thing = ({ thing = 1, style, ...props }: ThingProps) => {
//...
}

This however works perfectly:

interface ThingProps extends React.HTMLAttributes<HTMLDivElement> {
  thing?: number
}

export const Thing = ({ thing = 1, style, ...props }: ThingProps & React.HTMLAttributes<HTMLDivElement>) => {
//...
}
@Cretezy
Copy link

Cretezy commented Jul 20, 2020

Same for me. This broke when upgrading from 7.20.0 to 7.20.1+ (ESLint 7.5.0)

@efeminella
Copy link

Same here, rolling back to 7.20.0 resolved the issue for now, seems the .1 patch broke this.

@timdorr
Copy link

timdorr commented Jul 27, 2020

Appears to be fixed in 7.20.4.

@ljharb ljharb closed this as completed Jul 28, 2020
ljharb pushed a commit to hank121314/eslint-plugin-react that referenced this issue Jul 31, 2020
…ript props interface extension and TSTypeAliasDeclaration

Fixes jsx-eslint#2654. Fixes jsx-eslint#2719. Fixes jsx-eslint#2703.
ljharb pushed a commit to hank121314/eslint-plugin-react that referenced this issue Jul 31, 2020
…ript props interface extension and TSTypeAliasDeclaration

Fixes jsx-eslint#2654. Fixes jsx-eslint#2719. Fixes jsx-eslint#2703.
ljharb pushed a commit to hank121314/eslint-plugin-react that referenced this issue Jul 31, 2020
…ript props interface extension and TSTypeAliasDeclaration

Fixes jsx-eslint#2654. Fixes jsx-eslint#2719. Fixes jsx-eslint#2703.
ljharb added a commit to hank121314/eslint-plugin-react that referenced this issue Aug 1, 2020
…ypescript props interface extension and TSTypeAliasDeclaration

Fixes jsx-eslint#2654. Fixes jsx-eslint#2719. Fixes jsx-eslint#2703.

Co-authored-by: Hank Chen <[email protected]>
Co-authored-by: Jordan Harband <[email protected]>
@kylemh
Copy link

kylemh commented Aug 3, 2020

I'm unfortunately still seeing this in certain scenarios.

Right now I'm seeing the issue with an example like so:

// `SelectableFileCardProps` and `DNDMovableToBoardItemProps` are interfaces in another file imported in here
// `SelectableFileCardProps` extends off of an another imported file in it's own file
interface DragDroppableFileShellProps extends
  SelectableFileCardProps, Pick<DNDMovableToBoardItemProps, 'onDragStart'>
{
  children: React.ReactNode;
}

@ljharb
Copy link
Member

ljharb commented Aug 3, 2020

@kylemh cross-file static analysis is not something that's done in most eslint plugins, and certainly not in this one; unless the TS eslint parser provides that information, it can't work (and i'd expect if it did provide that information, it would already work)

@kylemh
Copy link

kylemh commented Aug 3, 2020

Hmmm... Is there something I can do to get cross-file static analysis working or should I simply disable this rule?

@ljharb
Copy link
Member

ljharb commented Aug 3, 2020

The TypeScript eslint parser could certainly be updated to provide this information. I'd start by making test cases here, confirm that they fail, try to figure out where in the AST nodes the information is missing, and then file an issue/PR on the TS eslint parser.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
6 participants