Skip to content

Strict null check#6497

Merged
PavelVanecek merged 15 commits intomainfrom
strictNullCheck
Oct 25, 2025
Merged

Strict null check#6497
PavelVanecek merged 15 commits intomainfrom
strictNullCheck

Conversation

@PavelVanecek
Copy link
Collaborator

900 or so errors, mostly in tests and storybook -> 0

Closes #5768

@PavelVanecek PavelVanecek requested a review from Copilot October 23, 2025 07:07
Copy link
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

This PR enables strict null checks across the recharts codebase, addressing approximately 900 TypeScript errors primarily in tests and storybook configurations. The changes focus on making the codebase compatible with TypeScript's strictNullChecks compiler option.

Key changes:

  • Added strictNullChecks: true to test and storybook TypeScript configurations
  • Updated type annotations to explicitly handle null and undefined values
  • Added runtime null checks and assertions where needed
  • Fixed incorrect type expectations and fallback values

Reviewed Changes

Copilot reviewed 117 out of 118 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
test/tsconfig.json Enabled strictNullChecks compiler option
storybook/tsconfig.json Enabled strictNullChecks compiler option
test/**/*.spec.tsx Added null checks, type guards, and updated type annotations for test expectations
storybook/**/*.tsx Added null guards and updated type signatures for storybook components
src/util/types.ts Updated return types to allow ReactNode instead of restrictive JSX.Element
src/component/Legend.tsx Documented itemSorter prop to clarify null behavior
www/src/docs/**/*.tsx Fixed null handling in example components

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

@@ -94,8 +94,8 @@ const HighlightAndZoomLineChart = () => {
...prev,
refAreaLeft: undefined,
refAreaRight: undefined,
Copy link

Copilot AI Oct 23, 2025

Choose a reason for hiding this comment

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

[nitpick] The fallback logic uses initialState.left and initialState.right which are defined as 'dataMin' and 'dataMax' respectively. This is semantically correct, but the original code's intent ('dataMin'/'dataMax') is now obscured. Consider adding a comment explaining why these specific fallback values are used, or using the string literals directly if the initialState values could change.

Suggested change
refAreaRight: undefined,
refAreaRight: undefined,
// Fallback to initialState.left ('dataMin') and initialState.right ('dataMax') to reset zoom window to full data range.

Copilot uses AI. Check for mistakes.
const tooltipSettings1: TooltipPayloadConfiguration = {
positions: undefined,
settings: undefined,
settings: { nameKey: 'y' },
Copy link

Copilot AI Oct 23, 2025

Choose a reason for hiding this comment

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

[nitpick] The test previously used undefined for settings but now requires { nameKey: 'y' }. While this fixes the strict null check issue, verify that using 'y' as the nameKey is semantically correct for this test case and doesn't inadvertently change what behavior is being tested.

Suggested change
settings: { nameKey: 'y' },
settings: undefined,

Copilot uses AI. Check for mistakes.

describe('LineChart - test ref access', () => {
test('should allow access to the main SVG through the ref prop forwarded from CategoricalChart', () => {
expect.assertions(2);
Copy link

Copilot AI Oct 23, 2025

Choose a reason for hiding this comment

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

[nitpick] The addition of expect.assertions(2) is good practice to ensure the ref callback is actually invoked. However, the test logic was restructured to move assertions inside the ref callback. If the ref callback is never called, the test would fail with 'Expected 2 assertions, but received 0' rather than a more descriptive error. Consider if this is the desired failure mode.

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

Choose a reason for hiding this comment

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

Yeah that's the point.

Comment on lines +532 to +533
refAreaLeft: undefined,
refAreaRight: undefined,
Copy link

Copilot AI Oct 23, 2025

Choose a reason for hiding this comment

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

The initial state was changed from empty strings ('') to undefined. While this is more type-safe, verify that the logic in getAxisYDomain and the zoom handler correctly handles undefined vs empty string, as these may have been treated differently in conditional checks.

Copilot uses AI. Check for mistakes.
@codecov
Copy link

codecov bot commented Oct 23, 2025

Codecov Report

❌ Patch coverage is 62.50000% with 3 lines in your changes missing coverage. Please review.
✅ Project coverage is 93.45%. Comparing base (f259459) to head (750d046).
⚠️ Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
...Components/LineChart/HighlightAndZoomLineChart.tsx 0.00% 3 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #6497      +/-   ##
==========================================
- Coverage   93.45%   93.45%   -0.01%     
==========================================
  Files         431      431              
  Lines       39169    39168       -1     
  Branches     4552     4550       -2     
==========================================
- Hits        36607    36606       -1     
  Misses       2545     2545              
  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

codecov bot commented Oct 23, 2025

Bundle Report

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

Detailed changes
Bundle name Size Change
recharts/bundle-cjs 1.09MB 7 bytes (0.0%) ⬆️
recharts/bundle-es6 939.67kB 7 bytes (0.0%) ⬆️

Affected Assets, Files, and Routes:

view changes for bundle: recharts/bundle-es6

Assets Changed:

Asset Name Size Change Total Size Change (%)
cartesian/Scatter.js 1 bytes 21.52kB 0.0%
state/selectors/radialBarSelectors.js 1 bytes 11.24kB 0.01%
state/selectors/pieSelectors.js 1 bytes 4.27kB 0.02%
util/ReactUtils.js 1 bytes 2.62kB 0.04%
util/svgPropertiesAndEvents.js 1 bytes 1.95kB 0.05%
state/RechartsStoreProvider.js 1 bytes 1.92kB 0.05%
component/Customized.js 1 bytes 1.59kB 0.06%
view changes for bundle: recharts/bundle-cjs

Assets Changed:

Asset Name Size Change Total Size Change (%)
cartesian/Scatter.js 1 bytes 23.02kB 0.0%
state/selectors/radialBarSelectors.js 1 bytes 12.72kB 0.01%
state/selectors/pieSelectors.js 1 bytes 4.58kB 0.02%
util/ReactUtils.js 1 bytes 3.1kB 0.03%
state/RechartsStoreProvider.js 1 bytes 2.77kB 0.04%
component/Customized.js 1 bytes 2.38kB 0.04%
util/svgPropertiesAndEvents.js 1 bytes 2.23kB 0.04%

Copy link
Member

@ckifer ckifer left a comment

Choose a reason for hiding this comment

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

Nice 🚀🚀🚀

No more accidentally adding new ones now

@PavelVanecek PavelVanecek merged commit 75948d9 into main Oct 25, 2025
26 of 28 checks passed
@PavelVanecek PavelVanecek deleted the strictNullCheck branch October 25, 2025 00:58
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.

enable strictNullChecks in tsconfig.json

3 participants