Skip to content

Missing "data" prop on "Area" component, but chart still works (v2.x and v1.8.x) #2487

Description

@bennettdams
  • I have searched the issues of this repository and believe that this is not a duplicate.

Reproduction link

Edit on CodeSandbox

What is expected?

The Area component has no data prop. As you can see in the example, the chart still works when using that prop nevertheless.

What is actually happening?

I want to dynamically show areas in my composed chart. For that I'm splitting up the data and "map" in the render:

Example data

const areas = [
  {
    id: "area1",
    data: [
      { ts: 1, value: 5 },
      { ts: 2, value: 10 }
    ]
  },
  {
    id: "area2",
    data: [
      { ts: 1, value: 9 },
      { ts: 2, value: 16 }
    ]
  }
];

Render

<ComposedChart ...>
  ...
  <XAxis dataKey="ts" type="number" />
  ...
  {areas.map((area) => (
    <Area
      // @ts-ignore
      data={area.data}
      dataKey="value"
      key={area.id}
      ...
    />
  ))}
  ...
</ComposedChart>

This works perfectly fine and the chart renders correctly, but TypeScript says there's no data prop on an Area component (hence the // @ts-ignore in my example).

Is this just a missing type definition or is this somehow working because of other circumstances?

Please see my CodeSandbox for a working example.


This is also the case for earlier versions (v1.8.x).


Environment Info
Recharts v2.0.8
React v17.0.1
System any
Browser any

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions