Skip to content

Add a rule prefer-exact-props #1455

Closed
@julienw

Description

@julienw

With react and flow, it's very common to type props like this:

type Props = {
  prop1: string,
  prop2: number
};

However this makes it possible to pass other props as well, as by default objects in Flow are not exact. So this can hide an issue where the developer removed a prop but the caller still use it:

<Component prop1='foo' prop2={42} prop3='bar' />

Or made a typo (this example is possible is prop2 is optional):

<Component prop1='foo' porp2={42} />

To fix this with flow, the solution is to use exact objects:

type Props = {|
  prop1: string,
  prop2: number
|};

It would be useful to have an eslint rule to force this pattern.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions