Skip to content

Conversation

@Faithfinder
Copy link

@Faithfinder Faithfinder commented Feb 10, 2026

Summary

  • Adds in out (invariant) variance annotations to TData and TValue type parameters on all mutually recursive types in the ColumnDef/Column cycle (ColumnDefBase, Column, Cell, Header, CoreColumn, CoreCell, CoreHeader, HeaderContext, CellContext, GroupingColumnDef, and related ColumnDef variants)
  • Makes TableFeature's createCell/createColumn/createHeader methods generic over TValue so the invariant type parameter flows through correctly in implementation code
  • Propagates TValue to feature createColumn implementations and internal helpers (shouldAutoRemoveFilter) that were previously hardcoding Column<TData, unknown>
  • Fixes a bug where tsc silently drops type errors depending on file processing order, while the IDE (language server) correctly reports them

Root cause

TypeScript has a known variance computation bug with mutually recursive generic types (microsoft/TypeScript#44572, closed as Design Limitation). When tsc processes files in a certain order, the variance computation cycle causes it to bail out and cache TValue as [independent], making ColumnDef<Row, string> incorrectly assignable to ColumnDef<Row, unknown>. The official workaround is explicit variance annotations, introduced in TS 4.7 (microsoft/TypeScript#48240).

Reproduction

https://github.com/Faithfinder/ts-ide-cli-repro (main branch)

Fixes #6167
Related: #4241, #4382

Test plan

  • table-core type-checks cleanly (tsc --noEmit)
  • table-core unit tests pass (21/21)
  • react-table unit tests pass (8/8)
  • Verified against the repro — all 3 type errors are now correctly reported by tsc regardless of file order

🤖 Generated with Claude Code

Summary by CodeRabbit

  • Refactor
    • Improved TypeScript typing across the table core module by applying variance annotations to generic types, enhancing type safety and inference for consumers and tooling without changing runtime behavior or public functionality.

@changeset-bot
Copy link

changeset-bot bot commented Feb 10, 2026

⚠️ No Changeset found

Latest commit: acc27f0

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@coderabbitai
Copy link

coderabbitai bot commented Feb 10, 2026

Important

Review skipped

Draft detected.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
📝 Walkthrough

Walkthrough

Added explicit variance annotations (in out) to many generic type parameters across the table-core package and adjusted several unknown defaults to any. All edits are type-level only; no runtime logic or control flow was changed. (≈35 files touched; summary focuses on exported/public types.)

Changes

Cohort / File(s) Summary
Core types
packages/table-core/src/core/cell.ts, packages/table-core/src/core/column.ts, packages/table-core/src/core/headers.ts
Added in out variance annotations to exported interfaces: CellContext, CoreCell, CoreColumn, HeaderContext, and CoreHeader.
Primary types file
packages/table-core/src/types.ts
Systematic addition of in/out variance to many public generics (AccessorFn, Column/Cell/Header, ColumnDef* variants, ColumnDefExtensions, etc.) and several unknown defaults changed to any. Also narrowed several TableFeature.create* signatures to include a TValue generic.
Feature: ColumnGrouping
packages/table-core/src/features/ColumnGrouping.ts
Added in out variance to GroupingColumnDef generic parameters.
Feature: ColumnFaceting
packages/table-core/src/features/ColumnFaceting.ts
createColumn signature made generic over TValue and now accepts Column<TData, TValue>.
Feature: ColumnFiltering
packages/table-core/src/features/ColumnFiltering.ts
Introduced TValue generics and changed several function/typedef column parameter types from Column<TData, unknown>Column<TData, any> (and related signature updates).
Feature: ColumnOrdering
packages/table-core/src/features/ColumnOrdering.ts
createColumn signature made generic over TValue and now accepts Column<TData, TValue>.
Feature: GlobalFiltering
packages/table-core/src/features/GlobalFiltering.ts
getColumnCanGlobalFilter widened to accept Column<TData, any>; createColumn signature now generic over TValue and accepts Column<TData, TValue>.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Suggested reviewers

  • KevinVandy

Poem

🐰 Hopped through generics with ears held high,

In and out markers winked an approving eye.
Unknowns turned to any, the meadow's in tune,
Types now dance lightly beneath the moon. ✨

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately summarizes the main change: adding variance annotations to fix file-order-dependent type errors in TypeScript type checking.
Description check ✅ Passed The description is comprehensive and addresses the template requirements. It includes a detailed summary of changes, root cause analysis, reproduction steps, and test plan confirming testing was performed.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

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

✨ Finishing touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

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

@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.

Caution

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

⚠️ Outside diff range comments (1)
packages/table-core/src/core/headers.ts (1)

19-32: ⚠️ Potential issue | 🟡 Minor

HeaderContext is missing extends RowData constraint on TData.

Unlike CellContext<in out TData extends RowData, in out TValue> in cell.ts (line 4) and CoreHeader below (line 34), HeaderContext declares in out TData without the extends RowData bound. This appears to be a pre-existing inconsistency, but since this PR is cleaning up the type parameter declarations across the cycle, it's a good opportunity to fix it.

Proposed fix
-export interface HeaderContext<in out TData, in out TValue> {
+export interface HeaderContext<in out TData extends RowData, in out TValue> {

@Faithfinder Faithfinder force-pushed the fix/variance-annotations branch from 40b4466 to 20a7121 Compare February 10, 2026 17:23
@Faithfinder Faithfinder marked this pull request as draft February 10, 2026 17:25
Copy link

@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.

Caution

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

⚠️ Outside diff range comments (1)
packages/table-core/src/features/ColumnFiltering.ts (1)

44-47: ⚠️ Potential issue | 🟡 Minor

TransformFilterValueFn still uses Column<TData, unknown> — inconsistent with the any change on ColumnFilterAutoRemoveTestFn.

With Column now invariant in TValue, Column<TData, string> (or any non-unknown TValue) is no longer assignable to Column<TData, unknown>. ColumnFilterAutoRemoveTestFn (line 51) was correctly updated to Column<TData, any>, but TransformFilterValueFn was not. Both are callbacks on FilterFn that receive an optional Column parameter — they should be consistent.

Proposed fix
 export type TransformFilterValueFn<TData extends RowData> = (
   value: any,
-  column?: Column<TData, unknown>
+  column?: Column<TData, any>
 ) => unknown

Add `in out` (invariant) variance annotations to `TData` and `TValue`
type parameters on all mutually recursive types in the ColumnDef/Column
cycle (ColumnDefBase, Column, Cell, Header, CoreColumn, CoreCell,
CoreHeader, HeaderContext, CellContext, GroupingColumnDef, and related
ColumnDef variants).

This works around a known TypeScript variance computation bug
(microsoft/TypeScript#44572) where file processing order causes tsc to
incorrectly cache TValue as [independent], silently making
ColumnDef<Row, string> assignable to ColumnDef<Row, unknown>.

Also makes TableFeature's createCell/createColumn/createHeader methods
generic over TValue (instead of hardcoding unknown) so that the
invariant TValue flows through correctly in implementation code.

Fixes TanStack#6167
Related: TanStack#4241, TanStack#4382

Co-Authored-By: Claude Opus 4.6 <[email protected]>
@Faithfinder Faithfinder force-pushed the fix/variance-annotations branch from 20a7121 to acc27f0 Compare February 10, 2026 17:36
@Faithfinder Faithfinder marked this pull request as ready for review February 10, 2026 17:37
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.

tsc silently drops ColumnDef type errors depending on file processing order (TypeScript variance bug)

1 participant