Skip to content

More strictNullChecks refactoring#6446

Merged
ckifer merged 5 commits intomainfrom
strictNullChecks
Oct 17, 2025
Merged

More strictNullChecks refactoring#6446
ckifer merged 5 commits intomainfrom
strictNullChecks

Conversation

@PavelVanecek
Copy link
Copy Markdown
Collaborator

Description

Split the inRange method & friends to two code paths, got rid of undefined and optional properties.

Related Issue

#5768

333 errors -> 294

@PavelVanecek PavelVanecek requested a review from Copilot October 12, 2025 09:24
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

Stricter nullability and tooltip refactor to split cartesian/polar paths and remove optional/undefined-heavy props.

  • Introduces util/getActiveCoordinate.ts and refactors tooltip active coordinate and index calculations into separate cartesian and polar paths.
  • Tightens types across grid/axis/tick utilities and selectors (undefined vs null, required vs optional), and updates tests accordingly.
  • Simplifies getEveryNthWithCondition API by removing the predicate parameter and undefined return.

Reviewed Changes

Copilot reviewed 24 out of 27 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
www/src/docs/exampleComponents/PieChart/index.tsx Moves flexbox explanatory content out of the component into index wrapper.
www/src/docs/exampleComponents/PieChart/PieChartInFlexbox.tsx Removes wrapper/paragraph to avoid duplication; component now only renders the flex container and chart.
test/util/ChartUtils.spec.tsx Updates import path for calculateActiveTickIndex to new util/getActiveCoordinate.
test/cartesian/CartesianGrid.spec.tsx Types tests’ generators as Vitest mocks and adjusts expectations for syncWithTicks (undefined → false). Adds expectLastCalledWith helper.
src/util/types.ts Redefines RangeObj to be PolarViewBoxRequired plus required angle/radius, removing cartesian fields.
src/util/getEveryNthWithCondition.ts Removes predicate and undefined return; always returns a stepped subset.
src/util/getActiveCoordinate.ts New module: cartesian/polar active coordinate helpers, in-range check, and calculateActiveTickIndex.
src/util/YAxisUtils.tsx Changes ticks arg type to null instead of undefined.
src/util/TickUtils.ts getAngledTickWidth accepts angle: number
src/util/PolarUtils.ts narrows exports; inRangeOfSector now accepts ChartPointer instead of raw coordinates.
src/util/ChartUtils.ts Removes inRange/getActiveCoordinate/calculateActiveTickIndex; adds calculateCartesianTooltipPos/calculatePolarTooltipPos.
src/state/selectors/tooltipSelectors.ts selectDomainOfAllAppliedNumericalValuesIncludingErrorValues can return undefined.
src/state/selectors/selectors.ts Refactors active tooltip prop combination into separate cartesian/polar code paths; updates selector arg types to allow undefined.
src/state/selectors/combiners/combineTooltipPayload.ts tooltipEventType argument is optional.
src/state/selectors/axisSelectors.ts Returns undefined (not null) for missing axis props.
src/component/Tooltip.tsx Safely handles possibly undefined selector results; finalIsActive defaults to false.
src/component/Label.tsx labelRef types accept null.
src/cartesian/getTicks.ts Loosens/optionalizes several GetTicksInput properties for strict null checks.
src/cartesian/CartesianGrid.tsx Adds defaultCartesianGridProps, positive-number validation, undefined-safe generator inputs, and width/height fallbacks.
scripts/snapshots/*Files.txt Adds getActiveCoordinate outputs to published bundles.
eslint.config.mjs Lints: ignore docs index.tsx files to allow default exports.

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

@@ -1,5 +1,5 @@
import React from 'react';
import { describe, test, it, expect, vi } from 'vitest';
import { describe, test, it, expect, vi, Mock } from 'vitest';
Copy link

Copilot AI Oct 12, 2025

Choose a reason for hiding this comment

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

Mock is a type in Vitest and should be imported as a type-only import; importing it as a value can cause a runtime error ('does not provide an export named Mock'). Replace with a type-only import.

Suggested change
import { describe, test, it, expect, vi, Mock } from 'vitest';
import { describe, test, it, expect, vi } from 'vitest';
import type { Mock } from 'vitest';

Copilot uses AI. Check for mistakes.

it('should pass props to the generator', () => {
const horizontalCoordinatesGenerator: HorizontalCoordinatesGenerator = vi.fn().mockReturnValue([]);
const horizontalCoordinatesGenerator: Mock<HorizontalCoordinatesGenerator> = vi.fn().mockReturnValue([]);
Copy link

Copilot AI Oct 12, 2025

Choose a reason for hiding this comment

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

Incorrect Mock typing: Vitest's Mock expects argument and return generics, not a function type. Use MockedFunction (or Mock<Parameters, ReturnType>) and import it as a type. Example: import type { MockedFunction } from 'vitest'; const horizontalCoordinatesGenerator: MockedFunction = vi.fn().mockReturnValue([]);

Copilot uses AI. Check for mistakes.
Comment on lines +12 to 24
export function getEveryNthWithCondition<Type>(array: ReadonlyArray<Type>, n: number): ReadonlyArray<Type> {
if (n < 1) {
return [];
}
if (n === 1 && isValid === undefined) {
if (n === 1) {
return array;
}
const result: Type[] = [];
for (let i = 0; i < array.length; i += n) {
if (isValid === undefined || isValid(array[i]) === true) {
result.push(array[i]);
} else {
return undefined;
}
result.push(array[i]);
}
return result;
}
Copy link

Copilot AI Oct 12, 2025

Choose a reason for hiding this comment

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

This change removes the isValid predicate parameter and the undefined return case, altering the exported function's signature and behavior. Since getEveryNthWithCondition is part of the published types (see snapshots), this is a breaking change for consumers. To preserve backwards compatibility, consider adding an overloaded signature that still accepts the optional predicate (ignoring it internally), or introduce a new function (e.g., getEveryNth) while keeping the old API deprecated but intact.

Copilot uses AI. Check for mistakes.
Copy link
Copy Markdown
Collaborator Author

@PavelVanecek PavelVanecek Oct 12, 2025

Choose a reason for hiding this comment

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

This is exported for internal use but it's not a public API (not exported from index.ts). This parameter is never used internally.

@codecov
Copy link
Copy Markdown

codecov bot commented Oct 12, 2025

Codecov Report

❌ Patch coverage is 98.10726% with 6 lines in your changes missing coverage. Please review.
✅ Project coverage is 93.83%. Comparing base (0da6676) to head (2a64769).
⚠️ Report is 10 commits behind head on main.

Files with missing lines Patch % Lines
src/state/selectors/selectors.ts 97.40% 2 Missing ⚠️
src/util/getActiveCoordinate.ts 98.48% 2 Missing ⚠️
src/state/selectors/axisSelectors.ts 50.00% 1 Missing ⚠️
src/util/ChartUtils.ts 88.88% 1 Missing ⚠️
Additional details and impacted files
@@           Coverage Diff           @@
##             main    #6446   +/-   ##
=======================================
  Coverage   93.83%   93.83%           
=======================================
  Files         417      418    +1     
  Lines       38423    38488   +65     
  Branches     4502     4503    +1     
=======================================
+ Hits        36053    36114   +61     
- Misses       2353     2357    +4     
  Partials       17       17           

☔ 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
Copy Markdown

codecov bot commented Oct 12, 2025

Bundle Report

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

Detailed changes
Bundle name Size Change
recharts/bundle-cjs 1.08MB 4.04kB (0.38%) ⬆️
recharts/bundle-es6 933.14kB 3.85kB (0.41%) ⬆️
recharts/bundle-umd 499.24kB 1.46kB (0.29%) ⬆️

Affected Assets, Files, and Routes:

view changes for bundle: recharts/bundle-es6

Assets Changed:

Asset Name Size Change Total Size Change (%)
state/selectors/axisSelectors.js 5 bytes 52.11kB 0.01%
util/ChartUtils.js -4.18kB 16.36kB -20.35%
cartesian/CartesianGrid.js 201 bytes 14.76kB 1.38%
component/Tooltip.js 163 bytes 7.59kB 2.19%
util/getActiveCoordinate.js (New) 6.41kB 6.41kB 100.0% 🚀
state/selectors/selectors.js 1.45kB 6.27kB 30.07% ⚠️
util/types.js -94 bytes 5.69kB -1.63%
util/PolarUtils.js -5 bytes 4.63kB -0.11%
util/getEveryNthWithCondition.js -104 bytes 756 bytes -12.09%
view changes for bundle: recharts/bundle-cjs

Assets Changed:

Asset Name Size Change Total Size Change (%)
state/selectors/axisSelectors.js 5 bytes 61.71kB 0.01%
util/ChartUtils.js -4.34kB 18.21kB -19.24%
cartesian/CartesianGrid.js 224 bytes 15.95kB 1.42%
component/Tooltip.js 163 bytes 8.67kB 1.92%
state/selectors/selectors.js 1.5kB 7.88kB 23.46% ⚠️
util/getActiveCoordinate.js (New) 6.91kB 6.91kB 100.0% 🚀
util/types.js -94 bytes 5.97kB -1.55%
util/PolarUtils.js -221 bytes 5.1kB -4.15%
util/getEveryNthWithCondition.js -104 bytes 890 bytes -10.46%
view changes for bundle: recharts/bundle-umd

Assets Changed:

Asset Name Size Change Total Size Change (%)
Recharts.js 1.46kB 499.24kB 0.29%

@PavelVanecek PavelVanecek requested a review from ckifer October 14, 2025 12:08
@ckifer ckifer merged commit 9bbaa5d into main Oct 17, 2025
28 checks passed
@ckifer ckifer deleted the strictNullChecks branch October 17, 2025 05:45
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.

3 participants