Skip to content

Commit

Permalink
fix: allow TValue to be specified in display and group column helpers
Browse files Browse the repository at this point in the history
Normally, this is not an issue, since ColumnDef is contravariant with respect to TValue. However, the user might extend BaseColumnDef or another constituent of ColumnDef such that ColumnDef becomes invariant with respect to TValue. In that case, DisplayColumnDef<TData, unknown> is no longer assignable to ColumnDef<TData, TValue>. By adding TValue as a generic argument to display and group helpers, Typescript can infer the required type of TValue.
  • Loading branch information
Lucas Treffenstädt committed Jul 18, 2024
1 parent 3f0e5d2 commit 3eb37bd
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions packages/table-core/src/columnHelper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,12 @@ export type ColumnHelper<TData extends RowData> = {
) => TAccessor extends AccessorFn<TData>
? AccessorFnColumnDef<TData, TValue>
: AccessorKeyColumnDef<TData, TValue>
display: (column: DisplayColumnDef<TData>) => DisplayColumnDef<TData, unknown>
group: (column: GroupColumnDef<TData>) => GroupColumnDef<TData, unknown>
display: <TValue = unknown>(
column: DisplayColumnDef<TData, TValue>
) => DisplayColumnDef<TData, TValue>
group: <TValue = unknown>(
column: GroupColumnDef<TData, TValue>
) => GroupColumnDef<TData, TValue>
}

export function createColumnHelper<
Expand Down

0 comments on commit 3eb37bd

Please sign in to comment.