Skip to content

refactor: enhance type definitions for LabelList and Area components#6936

Merged
ckifer merged 1 commit intomainfrom
types
Jan 29, 2026
Merged

refactor: enhance type definitions for LabelList and Area components#6936
ckifer merged 1 commit intomainfrom
types

Conversation

@PavelVanecek
Copy link
Collaborator

@PavelVanecek PavelVanecek commented Jan 27, 2026

Description

  • Removed as cast from baseLine
  • changed [number, number] type to Array of unknown as that better describes what is going on - nothing here guarantees numbers, and indeed charts with two categorical axes are not going to have numeric data in them.
  • Removed couple of ts-expect-errors

Related Issue

#6645

Summary by CodeRabbit

Release Notes

  • Refactor
    • Improved type consistency and validation for area rendering, baseline handling, and label components.
    • Enhanced runtime type safety for renderable content through strengthened type definitions across components.

✏️ Tip: You can customize this high-level summary in your review settings.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Jan 27, 2026

Walkthrough

This PR introduces a new BaseLineType type alias in the Curve component and applies it across the codebase to improve type consistency. Additionally, type signatures are updated for generics in LabelList and related components, and a new type guard function is added for renderable text validation.

Changes

Cohort / File(s) Summary
Baseline Type Definition
src/shape/Curve.tsx
Exports new BaseLineType alias (number | ReadonlyArray<NullableCoordinate>); updates CurveProps.baseLine to use the alias.
Area Component Type Updates
src/cartesian/Area.tsx
Imports and applies BaseLineType throughout: updates InternalAreaProps.baseLine, AreaProps.baseLine, component parameters (StaticArea, VerticalRect, HorizontalRect, ClipRect), animation refs, and local variables. Expands BaseValueCoordinate to be generic with payload: DataPointType | undefined. Widens computeArea's valueAsArray to ReadonlyArray<unknown> | undefined. Adds Array.isArray() guards for baseline range rendering.
LabelList and Text Components
src/component/LabelList.tsx, src/component/Text.tsx
Makes LabelListEntry generic; updates value to unknown and payload to DataPointItem. Changes valueAccessor return type to RenderableText. Refactors defaultAccessor to normalize arrays and validate renderability. Adds new exported isRenderableText() type guard function.
Area Selectors
src/state/selectors/areaSelectors.ts
Relaxes AreaPointItem.value type from strict [number, number] tuple to ReadonlyArray<unknown>.
Example/Test File
www/src/components/GuideView/ZIndex/PrahaMetro.tsx
Removes ts-expect-error suppression; logic unchanged.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related PRs

  • Introduces type-level refactors aligned with strict-tsconfig changes affecting Area, Curve, LabelList, and Text components
  • Directly applies the BaseLineType exported from Curve and coordinates baseline typing across Area component
  • Modifies Area component type signatures and public API consistency

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 12.50% 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 accurately summarizes the main objective: type definition enhancements for LabelList and Area components, which aligns with the changeset.
Description check ✅ Passed The description covers key changes and links to the related issue, but missing sections from the template like testing details and types of changes checklist.

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

✨ Finishing touches
  • 📝 Generate docstrings

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.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 2

🤖 Fix all issues with AI agents
In `@src/cartesian/Area.tsx`:
- Line 85: The type alias BaseValueCoordinate currently uses an `any` default
for its generic (type BaseValueCoordinate<DataPointType = any>); change the
default to a non-`any` type (for example `unknown`) so the signature becomes
BaseValueCoordinate<DataPointType = unknown> and ensure the payload remains
DataPointType | undefined; update any related usages that relied on implicit
`any` to explicitly type the DataPointType where needed (look for the
BaseValueCoordinate symbol and places that instantiate it).

In `@src/component/LabelList.tsx`:
- Line 14: The generic default for LabelListEntry currently uses `any`
(LabelListEntry<DataPointItem = any>); change the default to `unknown` to comply
with the guideline (LabelListEntry<DataPointItem = unknown>) and update any code
that relies on implicit `any` by adding proper type guards or narrowing where
LabelListEntry is consumed (e.g., places constructing or accessing DataPointItem
should be adjusted to assert or narrow the unknown type).

* Our base value array has payload in it, and we expose it externally too.
*/
type BaseValueCoordinate = NullableCoordinate & { payload: any };
type BaseValueCoordinate<DataPointType = any> = NullableCoordinate & { payload: DataPointType | undefined };
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟡 Minor

Avoid any as default generic parameter.

Per coding guidelines: "Never use any type (implicit or explicit) in TypeScript code."

Suggested fix
-type BaseValueCoordinate<DataPointType = any> = NullableCoordinate & { payload: DataPointType | undefined };
+type BaseValueCoordinate<DataPointType = unknown> = NullableCoordinate & { payload: DataPointType | undefined };
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
type BaseValueCoordinate<DataPointType = any> = NullableCoordinate & { payload: DataPointType | undefined };
type BaseValueCoordinate<DataPointType = unknown> = NullableCoordinate & { payload: DataPointType | undefined };
🤖 Prompt for AI Agents
In `@src/cartesian/Area.tsx` at line 85, The type alias BaseValueCoordinate
currently uses an `any` default for its generic (type
BaseValueCoordinate<DataPointType = any>); change the default to a non-`any`
type (for example `unknown`) so the signature becomes
BaseValueCoordinate<DataPointType = unknown> and ensure the payload remains
DataPointType | undefined; update any related usages that relied on implicit
`any` to explicitly type the DataPointType where needed (look for the
BaseValueCoordinate symbol and places that instantiate it).

import { isRenderableText, RenderableText } from './Text';

export interface LabelListEntry {
export interface LabelListEntry<DataPointItem = any> {
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟡 Minor

Avoid any as default generic parameter.

The coding guidelines specify: "Never use any type (implicit or explicit) in TypeScript code. Prefer unknown over any."

Consider using unknown as the default type parameter:

Suggested fix
-export interface LabelListEntry<DataPointItem = any> {
+export interface LabelListEntry<DataPointItem = unknown> {
🤖 Prompt for AI Agents
In `@src/component/LabelList.tsx` at line 14, The generic default for
LabelListEntry currently uses `any` (LabelListEntry<DataPointItem = any>);
change the default to `unknown` to comply with the guideline
(LabelListEntry<DataPointItem = unknown>) and update any code that relies on
implicit `any` by adding proper type guards or narrowing where LabelListEntry is
consumed (e.g., places constructing or accessing DataPointItem should be
adjusted to assert or narrow the unknown type).

@codecov
Copy link

codecov bot commented Jan 27, 2026

Codecov Report

❌ Patch coverage is 88.23529% with 2 lines in your changes missing coverage. Please review.
✅ Project coverage is 94.29%. Comparing base (1f8b5be) to head (12bdfd1).
⚠️ Report is 7 commits behind head on main.

Files with missing lines Patch % Lines
src/component/LabelList.tsx 75.00% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #6936      +/-   ##
==========================================
- Coverage   94.29%   94.29%   -0.01%     
==========================================
  Files         571      571              
  Lines       56002    56011       +9     
  Branches     5222     5226       +4     
==========================================
+ Hits        52807    52814       +7     
- Misses       3186     3188       +2     
  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
Copy link

codecov bot commented Jan 27, 2026

Bundle Report

Changes will increase total bundle size by 353 bytes (0.01%) ⬆️. This is within the configured threshold ✅

Detailed changes
Bundle name Size Change
recharts/bundle-cjs 1.21MB 69 bytes (0.01%) ⬆️
recharts/bundle-umd 530.7kB 140 bytes (0.03%) ⬆️
recharts/bundle-es6 1.05MB 144 bytes (0.01%) ⬆️

Affected Assets, Files, and Routes:

view changes for bundle: recharts/bundle-cjs

Assets Changed:

Asset Name Size Change Total Size Change (%)
cartesian/Area.js -131 bytes 29.33kB -0.44%
component/Text.js 203 bytes 10.8kB 1.92%
shape/Curve.js 20 bytes 7.77kB 0.26%
component/LabelList.js -23 bytes 6.97kB -0.33%
view changes for bundle: recharts/bundle-es6

Assets Changed:

Asset Name Size Change Total Size Change (%)
cartesian/Area.js -131 bytes 27.46kB -0.47%
component/Text.js 149 bytes 9.47kB 1.6%
shape/Curve.js 20 bytes 6.6kB 0.3%
component/LabelList.js 106 bytes 5.86kB 1.84%
view changes for bundle: recharts/bundle-umd

Assets Changed:

Asset Name Size Change Total Size Change (%)
Recharts.js 140 bytes 530.7kB 0.03%

@github-actions
Copy link
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 a92e35d into main Jan 29, 2026
47 of 48 checks passed
@ckifer ckifer deleted the types branch January 29, 2026 02:41
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