Skip to content

Typescript strict#6646

Merged
ckifer merged 1 commit intomainfrom
tsconfig-strict
Nov 18, 2025
Merged

Typescript strict#6646
ckifer merged 1 commit intomainfrom
tsconfig-strict

Conversation

@PavelVanecek
Copy link
Collaborator

@PavelVanecek PavelVanecek commented Nov 17, 2025

Description

There's more strict settings to turn on so let's kick it off.

One change to call out is the getNiceTickValues. It was wrapped in a custom memoize implementation that throws away types. strictFunctionTypes settings flags that as a problem (and it should). I tried to replace it with memoize from es-toolkit but turns out that es-toolkit only supports memoizing functions with a single argument. We have 3 arguments. Because we only ever use this function inside an already memoized selector, I figured we might just as well throw away the extra memo layer instead of reimplementing memoize we don't need.

Other changes are removing unused code, and fixing types. There are around 400 errors total to go through.

Related Issue

#6645

Summary by CodeRabbit

  • Bug Fixes

    • Fixed potential null reference errors in cache eviction when cache capacity is reached.
  • Chores

    • Enhanced TypeScript compiler strictness options for improved type safety.
    • Removed unused memoization and interpolation utilities.
    • Refined internal type annotations across multiple modules for better code stability.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Nov 17, 2025

Walkthrough

This pull request refactors type annotations, removes utility functions and memoization wrappers, adds defensive null-checking in cache eviction, and tightens TypeScript compiler strictness settings across the codebase.

Changes

Cohort / File(s) Summary
Type System Refinements
src/state/touchEventsMiddleware.ts, src/state/zIndexSlice.ts, src/util/YAxisUtils.tsx, src/util/useElementOffset.ts
Generic type parameter added to createListenerMiddleware, reduce callback parameters more precisely typed, forEach callback parameter type narrowed, and DOM node parameter type broadened from HTMLDivElement to HTMLElement.
Memoization Removal & API Cleanup
src/util/scale/getNiceTickValues.ts, src/util/scale/util/utils.ts, src/util/scale/util/arithmetic.ts
Removed memoize utility function and unwrapped memoization from exported functions; renamed internal functions to public exports (getNiceTickValuesFngetNiceTickValues); removed three interpolation utilities (interpolateNumber, uninterpolateNumber, uninterpolateTruncation).
Cache Safety
src/util/LRUCache.ts
Added null/undefined guard before deleting LRU key during cache eviction.
Test Updates
test/util/scale/arithmetic.spec.ts, test/util/scale/utils.spec.ts
Removed test suites for deleted interpolation functions and memoize utility; imports cleaned up accordingly.
TypeScript Configuration
tsconfig.json
Enabled strictness flags (strictBindCallApply, strictBuiltinIteratorReturn, strictPropertyInitialization, noImplicitThis, useUnknownInCatchVariables); disabled noUncheckedIndexedAccess; added TODO comment for strictFunctionTypes: false.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

  • src/util/LRUCache.ts: Logic change warrants verification that the null-check doesn't mask underlying issues or alter intended eviction behavior.
  • src/util/scale/getNiceTickValues.ts, src/util/scale/util/arithmetic.ts, src/util/scale/util/utils.ts: Public API reductions and memoization removal require downstream usage audit to ensure no unexpected performance regression or broken imports elsewhere in the codebase.
  • tsconfig.json: Strictness changes may surface type errors in code not shown in this diff; confirm compatibility with existing type assertions.

Possibly related PRs

Suggested reviewers

  • ckifer

Pre-merge checks and finishing touches

✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title 'Typescript strict' clearly and concisely summarizes the main change—enabling stricter TypeScript compiler settings.
Description check ✅ Passed The description covers the main objective, provides clear motivation (strictFunctionTypes issue), and explains the getNiceTickValues refactoring decision.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
✨ 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 tsconfig-strict

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: 0

🧹 Nitpick comments (1)
src/util/LRUCache.ts (1)

9-11: Add validation for maxSize to prevent edge cases.

While the null check added in lines 27-29 is a good defensive measure, it would be better to validate that maxSize > 0 in the constructor. If maxSize is 0 or negative, the eviction logic could behave unexpectedly (the condition on line 25 would be true even for an empty cache).

Apply this diff to add validation:

 constructor(maxSize: number) {
+  if (maxSize <= 0) {
+    throw new Error('maxSize must be greater than 0');
+  }
   this.maxSize = maxSize;
 }
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 7d92152 and bdb65ee.

📒 Files selected for processing (11)
  • src/state/touchEventsMiddleware.ts (1 hunks)
  • src/state/zIndexSlice.ts (1 hunks)
  • src/util/LRUCache.ts (1 hunks)
  • src/util/YAxisUtils.tsx (1 hunks)
  • src/util/scale/getNiceTickValues.ts (5 hunks)
  • src/util/scale/util/arithmetic.ts (1 hunks)
  • src/util/scale/util/utils.ts (0 hunks)
  • src/util/useElementOffset.ts (1 hunks)
  • test/util/scale/arithmetic.spec.ts (1 hunks)
  • test/util/scale/utils.spec.ts (1 hunks)
  • tsconfig.json (1 hunks)
💤 Files with no reviewable changes (1)
  • src/util/scale/util/utils.ts
🧰 Additional context used
🧬 Code graph analysis (2)
src/state/touchEventsMiddleware.ts (1)
src/state/store.ts (1)
  • RechartsRootState (94-94)
src/util/scale/getNiceTickValues.ts (3)
src/index.ts (1)
  • getNiceTickValues (117-117)
src/util/scale/index.ts (2)
  • getNiceTickValues (1-1)
  • getTickValuesFixedDomain (1-1)
src/util/types.ts (1)
  • NumberDomain (686-686)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
  • GitHub Check: Build, Test, Pack
🔇 Additional comments (12)
src/util/useElementOffset.ts (1)

53-53: LGTM! Type consistency improved.

The parameter type widening from HTMLDivElement | null to HTMLElement | null aligns the implementation with the exported SetElementOffset type signature (line 40). Since the function only uses getBoundingClientRect() which is available on all HTMLElement instances, this change is safe and makes the hook more flexible.

src/util/LRUCache.ts (1)

27-29: LGTM! Defensive null check improves type safety.

The null check before deleting firstKey is appropriate for strict TypeScript compliance. While firstKey should never be null/undefined in normal operation (since we're in a branch where cache.size >= maxSize), this check:

  • Satisfies strict TypeScript typing where Map.keys().next().value is typed as K | undefined
  • Provides defensive protection against edge cases
src/util/YAxisUtils.tsx (1)

29-29: LGTM! Type annotation aligns with function parameter.

The explicit type annotation ensures the callback parameter type matches the ticks parameter type, which is required for strict TypeScript settings.

src/state/zIndexSlice.ts (1)

35-35: LGTM! Explicit type annotations for strict mode.

The explicit type annotations on the reduce callback parameters and return type are necessary for stricter TypeScript settings and improve code clarity.

src/state/touchEventsMiddleware.ts (1)

14-14: LGTM! Type parameter ensures correct state typing.

Adding the RechartsRootState type parameter to createListenerMiddleware ensures the middleware has properly typed state access, which aligns with the ListenerEffectAPI<RechartsRootState, AppDispatch> usage on line 20.

tsconfig.json (1)

14-23: LGTM! Progressive enablement of strict TypeScript options.

The incremental approach to enabling strict TypeScript settings is appropriate for a large codebase. The TODO comments on lines 16 and 22 clearly document the remaining work items referenced in issue #6645.

The enabled options (strictBindCallApply, strictBuiltinIteratorReturn, strictPropertyInitialization, noImplicitAny, noImplicitThis, useUnknownInCatchVariables) represent solid progress toward full strictness.

test/util/scale/utils.spec.ts (1)

2-2: LGTM! Consistent with memoize removal.

The removal of the memoize import and its associated test suite aligns with the broader refactoring to remove memoization from the codebase.

test/util/scale/arithmetic.spec.ts (1)

3-3: LGTM! Test cleanup aligns with implementation changes.

The removal of tests for interpolation utilities is consistent with their removal from the arithmetic module.

src/util/scale/getNiceTickValues.ts (3)

7-7: LGTM! Consistent with memoize removal.

The removal of the memoize import aligns with the broader refactoring effort.


175-199: All call sites are properly memoized through parent selectors.

The only production call to getNiceTickValues occurs at src/state/selectors/axisSelectors.ts:1203 within the combineNiceTicks function, which is used as a result selector in a createSelector memoized selector (line 1224). The memoization is applied at the selector level via reselect's createSelector, making the function-level memoization redundant. No other production call sites were found outside memoized contexts.


210-237: Remove memoization concern — getTickValuesFixedDomain is already protected by selector memoization.

The function is called exclusively within selectNiceTicks (src/state/selectors/axisSelectors.ts:1218), which uses createSelector from reselect. This automatically memoizes the result based on input selector dependencies (selectAxisDomain, selectAxisSettings, selectRealScaleType), so the removal of internal memoization poses no performance risk. The selector pattern provides the necessary caching layer.

src/util/scale/util/arithmetic.ts (1)

54-54: Removal of interpolation utilities verified.

Search confirms that interpolateNumber, uninterpolateNumber, and uninterpolateTruncation have no remaining references in the codebase. Safe to remove from exports.

@codecov
Copy link

codecov bot commented Nov 17, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 94.17%. Comparing base (7d92152) to head (bdb65ee).
⚠️ Report is 3 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #6646      +/-   ##
==========================================
- Coverage   94.17%   94.17%   -0.01%     
==========================================
  Files         494      494              
  Lines       41666    41638      -28     
  Branches     4823     4813      -10     
==========================================
- Hits        39240    39212      -28     
  Misses       2421     2421              
  Partials        5        5              

☔ 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 Nov 17, 2025

Bundle Report

Changes will decrease total bundle size by 4.71kB (-0.18%) ⬇️. This is within the configured threshold ✅

Detailed changes
Bundle name Size Change
recharts/bundle-cjs 1.13MB -2.26kB (-0.2%) ⬇️
recharts/bundle-es6 976.73kB -2.04kB (-0.21%) ⬇️
recharts/bundle-umd 513.16kB -409 bytes (-0.08%) ⬇️

Affected Assets, Files, and Routes:

view changes for bundle: recharts/bundle-es6

Assets Changed:

Asset Name Size Change Total Size Change (%)
util/scale/getNiceTickValues.js -78 bytes 8.33kB -0.93%
util/scale/util/utils.js -538 bytes 2.03kB -20.97%
util/LRUCache.js 40 bytes 1.35kB 3.05%
util/scale/util/arithmetic.js -1.46kB 1.29kB -53.13%
view changes for bundle: recharts/bundle-cjs

Assets Changed:

Asset Name Size Change Total Size Change (%)
util/scale/getNiceTickValues.js -93 bytes 9.21kB -1.0%
util/scale/util/utils.js -576 bytes 2.31kB -19.98%
util/scale/util/arithmetic.js -1.63kB 1.53kB -51.55%
util/LRUCache.js 40 bytes 1.48kB 2.77%
view changes for bundle: recharts/bundle-umd

Assets Changed:

Asset Name Size Change Total Size Change (%)
Recharts.js -409 bytes 513.16kB -0.08%

@ckifer ckifer merged commit fa4782e into main Nov 18, 2025
29 checks passed
@ckifer ckifer deleted the tsconfig-strict branch November 18, 2025 05: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