-
-
Notifications
You must be signed in to change notification settings - Fork 3.5k
fix: add variance annotations to fix file-order-dependent type errors #6168
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
|
|
Important Review skippedDraft detected. Please check the settings in the CodeRabbit UI or the You can disable this status message by setting the Use the checkbox below for a quick retry:
📝 WalkthroughWalkthroughAdded explicit variance annotations ( Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing touches🧪 Generate unit tests (beta)
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. Comment |
There was a problem hiding this 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
HeaderContextis missingextends RowDataconstraint onTData.Unlike
CellContext<in out TData extends RowData, in out TValue>incell.ts(line 4) andCoreHeaderbelow (line 34),HeaderContextdeclaresin out TDatawithout theextends RowDatabound. 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> {
40b4466 to
20a7121
Compare
There was a problem hiding this 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
TransformFilterValueFnstill usesColumn<TData, unknown>— inconsistent with theanychange onColumnFilterAutoRemoveTestFn.With
Columnnow invariant inTValue,Column<TData, string>(or any non-unknownTValue) is no longer assignable toColumn<TData, unknown>.ColumnFilterAutoRemoveTestFn(line 51) was correctly updated toColumn<TData, any>, butTransformFilterValueFnwas not. Both are callbacks onFilterFnthat receive an optionalColumnparameter — 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 <noreply@anthropic.com>
20a7121 to
acc27f0
Compare
Summary
in out(invariant) variance annotations toTDataandTValuetype parameters on all mutually recursive types in theColumnDef/Columncycle (ColumnDefBase,Column,Cell,Header,CoreColumn,CoreCell,CoreHeader,HeaderContext,CellContext,GroupingColumnDef, and relatedColumnDefvariants)TableFeature'screateCell/createColumn/createHeadermethods generic overTValueso the invariant type parameter flows through correctly in implementation codeTValueto featurecreateColumnimplementations and internal helpers (shouldAutoRemoveFilter) that were previously hardcodingColumn<TData, unknown>tscsilently drops type errors depending on file processing order, while the IDE (language server) correctly reports themRoot cause
TypeScript has a known variance computation bug with mutually recursive generic types (microsoft/TypeScript#44572, closed as Design Limitation). When
tscprocesses files in a certain order, the variance computation cycle causes it to bail out and cacheTValueas[independent], makingColumnDef<Row, string>incorrectly assignable toColumnDef<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 (
mainbranch)Fixes #6167
Related: #4241, #4382
Test plan
table-coretype-checks cleanly (tsc --noEmit)table-coreunit tests pass (21/21)react-tableunit tests pass (8/8)tscregardless of file order🤖 Generated with Claude Code
Summary by CodeRabbit