Skip to content

In TypeScript, false positive for default-props-match-prop-types when importing and intersecting a type #3665

@robballou

Description

@robballou

Is there an existing issue for this?

  • I have searched the existing issues and my issue is unique
  • My issue appears in the command-line and not only in the text editor

Description Overview

In TypeScript, when defining the props with an intersection from an imported type, the default props will get marked as mismatched.

In types.ts:

export type SVGDefaultProps = {
  size: string | number;
}

In a component:

import type { SVGDefaultProps } from './types';

type ArrowProps = SVGDefaultProps & {
  direction: 'up' | 'down'
};

const defaultProps = {
  size: 16, // will get reported as failing react/default-props-match-prop-types
  direction: 'up',
};

But this will work if it's all in one file:

type SVGDefaultProps = {
  size: string | number;
}

type ArrowProps = SVGDefaultProps & {
  direction: 'up' | 'down'
};

const defaultProps = {
  size: 16,
  direction: 'up',
};

Expected Behavior

Importing a type and using it in an intersection will be behave the same as if the type is fully defined within a file.

eslint-plugin-react version

7.33.2

eslint version

v8.53

node version

v18.13

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