Skip to content

[TypeScript] Add DataConsumer type, and DataKey generics#6943

Merged
ckifer merged 2 commits into
mainfrom
DataConsumer
Feb 5, 2026
Merged

[TypeScript] Add DataConsumer type, and DataKey generics#6943
ckifer merged 2 commits into
mainfrom
DataConsumer

Conversation

@PavelVanecek

@PavelVanecek PavelVanecek commented Feb 1, 2026

Copy link
Copy Markdown
Collaborator

Description

Put the dataKey prop in a shared interface, then reuse the interface. Adds generics, though for now they are all just any, any.

Related Issue

#6645

Motivation and Context

Breaking down #6867 into smaller, manageable chunks.

Summary by CodeRabbit

  • Refactor

    • Updated TypeScript public types across many chart and axis components to add generic data/value parameters and a unified data consumer pattern, refining public props for Area, Bar, Line, Scatter, Pie, Radar, Treemap and axes.
  • Documentation

    • Adjusted comment handling to exempt Treemap's one-dimensional prop from a two-dimensional comment.
  • Chores

    • Simplified LineChart test setup and updated pre-push checks (replaced build step with type checking).

@coderabbitai

coderabbitai Bot commented Feb 1, 2026

Copy link
Copy Markdown
Contributor

Walkthrough

Generalizes chart data typing by introducing DataProvider/DataConsumer generics and migrating component-level dataKey typings into the new consumer/provider contracts; many public prop interfaces across cartesian, polar, and chart components were updated to include DataPointType/DataValueType generics.

Changes

Cohort / File(s) Summary
Core types
src/util/types.ts
Added DataProvider<DataPointType> and DataConsumer<DataPointType, DataValueType>; replaced DataKey<T> with DataKey<DataPointType, DataValueType>; made BaseAxisProps/RenderableAxisProps generic and tie them to DataConsumer.
Cartesian components
src/cartesian/Area.tsx, src/cartesian/Bar.tsx, src/cartesian/Brush.tsx, src/cartesian/Funnel.tsx, src/cartesian/Line.tsx, src/cartesian/Scatter.tsx
Public props gained DataPointType, DataValueType generics and now extend or require DataConsumer<..., ...>; removed dataKey from public prop interfaces; added DataConsumer imports.
Axes
src/cartesian/XAxis.tsx, src/cartesian/YAxis.tsx, src/cartesian/ZAxis.tsx, src/polar/PolarAngleAxis.tsx, src/polar/PolarRadiusAxis.tsx
Axis prop interfaces made generic (DataPointType, DataValueType) and now extend generic axis base types (RenderableAxisProps/BaseAxisProps).
Polar components
src/polar/Pie.tsx, src/polar/Radar.tsx, src/polar/RadialBar.tsx
Added DataConsumer to public/internal prop types; removed public dataKey where applicable; introduced generics for data/value types.
Chart components
src/chart/Treemap.tsx
Props and computeNode made generic; data, dataKey, and nameKey types updated to use DataPointType, DataValueType; DataConsumer added to props.
Utilities & tests
src/util/ChartUtils.ts, test/chart/LineChart.spec.tsx
Replaced RenderableAxisProps['type'] with AxisDomainTypeInput in ChartUtils; test updated to remove Customized wrapper.
Docs exceptions & hooks
omnidoc/commentSimilarityExceptions.ts, .husky/pre-push
Added Treemap comment-similarity exception; pre-push hook replaced build with check-types.

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~45 minutes

Possibly related PRs

Suggested labels

typescript

Suggested reviewers

  • ckifer
🚥 Pre-merge checks | ✅ 2 | ❌ 1
❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and concisely summarizes the main changes: introducing a DataConsumer type and adding generics to DataKey across the codebase.
Description check ✅ Passed The description is complete with all required template sections: Description (explains the core change), Related Issue (linked to #6645), Motivation and Context (references breaking down PR #6867), and key implementation details.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch DataConsumer

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@codecov

codecov Bot commented Feb 1, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 91.37%. Comparing base (866f061) to head (e72fc5f).
⚠️ Report is 8 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #6943   +/-   ##
=======================================
  Coverage   91.37%   91.37%           
=======================================
  Files         505      505           
  Lines       37754    37754           
  Branches     5271     5271           
=======================================
  Hits        34497    34497           
  Misses       3248     3248           
  Partials        9        9           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@codecov

codecov Bot commented Feb 1, 2026

Copy link
Copy Markdown

Bundle Report

Changes will increase total bundle size by 2.15kB (0.08%) ⬆️. This is within the configured threshold ✅

Detailed changes
Bundle name Size Change
recharts/bundle-cjs 1.23MB 1.07kB (0.09%) ⬆️
recharts/bundle-es6 1.06MB 1.07kB (0.1%) ⬆️

Affected Assets, Files, and Routes:

view changes for bundle: recharts/bundle-cjs

Assets Changed:

Asset Name Size Change Total Size Change (%)
util/types.js 1.07kB 9.23kB 13.18% ⚠️
view changes for bundle: recharts/bundle-es6

Assets Changed:

Asset Name Size Change Total Size Change (%)
util/types.js 1.07kB 8.82kB 13.89% ⚠️

@github-actions

github-actions Bot commented Feb 1, 2026

Copy link
Copy Markdown
Contributor

Staging Deployment Details

These deployments will remain available for 30 days.

To update snapshots: Comment /update-snapshots on this PR to automatically update the baseline screenshots.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
src/util/types.ts (1)

1354-1402: ⚠️ Potential issue | 🟡 Minor

Export DataConsumer and DataProvider from the public API entry point.

The DataProvider and DataConsumer interfaces have comprehensive JSDoc comments and clearly separate concerns between components that accept data arrays and those that extract values via dataKey. However, they are not exported from src/index.ts, yet they are extended by many exported components (Pie, Bar, Area, Line, Scatter, RadialBar, Radar, Brush, Treemap, ZAxis, and others).

Since users extending or typing these components would need to import from internal paths (recharts/util/types), this violates the guideline that all imports must use the public API entry point. Add these interfaces to the public API exports in src/index.ts to ensure proper API completeness.

@github-actions

github-actions Bot commented Feb 2, 2026

Copy link
Copy Markdown
Contributor

Staging Deployment Details

These deployments will remain available for 30 days.

To update snapshots: Comment /update-snapshots on this PR to automatically update the baseline screenshots.

@ckifer
ckifer merged commit f4dc8d5 into main Feb 5, 2026
48 checks passed
@PavelVanecek
PavelVanecek deleted the DataConsumer branch February 5, 2026 06:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants