Annotate cell values
Strongly typing a cell instance in TypeScript
TanStack · Type Alias
Cell is TanStack Table's feature-aware type for a table cell. It combines the core cell contract with cell-related types supplied by the enabled table features.
Cell is a feature-aware table-cell type. It combines the core cell contract with the type contributions supplied by the selected table features, while generics describe the feature set, row data, and cell value.
type Cell<TFeatures, TData, TValue> = Cell_Core<TFeatures, TData, TValue> & ExtractFeatureMapTypes<TFeatures, Cell_FeatureMap>| Name | Type | Description |
|---|---|---|
TFeatures | TableFeatures | The table features enabled for the cell type. |
TData | RowData | The row-data type associated with the cell. |
TValue | CellData | The value type held by the cell; defaults to CellData. |
A Cell type combining Cell_Core<TFeatures, TData, TValue> with feature-specific cell types.
import type { Cell, TableFeatures, RowData, CellData } from '@tanstack/table-core'
type Person = { name: string }
type Features = TableFeatures
declare const cell: Cell<Features, Person, string>
const value: string = cell.getValue()
console.log(value)This type annotation describes a cell containing a string value for a Person row.
Strongly typing a cell instance in TypeScript
Preserving feature-specific cell members
Connecting a cell to its row's domain object
Cell is generic over the enabled table features, the row-data type, and the cell-value type. Its definition combines Cell_Core with the feature-specific cell types extracted from the feature map.
Follow-up: Why is TFeatures constrained? It must extend TableFeatures so feature-specific additions can be derived safely from the table's supported feature set.
TData extends RowData and identifies the row shape associated with the cell. TValue extends CellData and represents the value held by that cell.
Follow-up: What happens when TValue is omitted? It defaults to CellData, which is broader than a domain-specific value type.
The alias is feature-aware rather than only a fixed core type: it intersects Cell_Core<TFeatures, TData, TValue> with ExtractFeatureMapTypes<TFeatures, Cell_FeatureMap>. This allows enabled features to augment the cell type.
Follow-up: How would you preserve those augmentations in application code? Use the same TFeatures type when declaring or passing cells instead of reducing the value to an unrelated base type.
Cell_CoreCellContextCellDataconstructCellTableFeaturesRowData