Skip to content
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

'x' is missing in props validation when extending interface and another type present with 'Prop' in it's name #2853

Closed
aximusnl opened this issue Nov 8, 2020 · 1 comment

Comments

@aximusnl
Copy link

aximusnl commented Nov 8, 2020

When Props are extending an interface that is imported AND another type is present with the name 'Prop' in it, react/proptypes is throwing a false positive.

How to reproduce

This is OK

interface PropsBase {
	foo: string;
}

type RenderProps  = {
	something: string;
}

interface Props extends PropsBase {
	bar: string;
}

const MyComponent = ({ foo, bar}: Props): JSX.Element => {
	return (
		<div>
			{foo} {bar}
		</div>
	)
}

export {
	MyComponent,
}

This shows an error: 'foo' is missing in props validation

PropsBase.ts

interface PropsBase {
	foo: string;
}

MyComponent.tsx

import { PropsBase } from './PropsBase';

interface Props extends PropsBase {
	bar: string;
}

type RenderProps  = {
	something: string;
}

const MyComponent = ({ foo, bar}: Props): JSX.Element => {
	return (
		<div>
			{foo} {bar}
		</div>
	)
}

export {
	MyComponent,
}
@aximusnl aximusnl changed the title 'x' is missing in props validation 'x' is missing in props validation when extending interface and another type present with 'Prop' in it's name Nov 8, 2020
@ljharb
Copy link
Member

ljharb commented Nov 8, 2020

This is expected - it’s the limits of static analysis. The linter can’t read other files, so it has no idea that foo exists in the other file.

@ljharb ljharb closed this as completed Nov 23, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

2 participants