Architecture decision record · ADR-0027

Column defs of any value type (AnyValue)

AnyValue is a brand interface ('~latticeAnyValue'), exported from @ember-lattice/core.

Status
Accepted
Deciders
Joe Gaudet
Created
Updated
PRD
PRD
Related
None

Context

TanStack types the table columns option and the columns of a group def as ColumnDef<TFeatures, TData, any>. Lattice has no any, so the port used ColumnDef<TFeatures, TData, unknown>. Thus a list of defs with different value types did not fit. An example is a ColumnDef<…, string> def and a ColumnDef<…, number> def in one list, written without columnHelper.

The cause is a cycle in the types. ColumnDef has cell and footer, which get a CellContext or a HeaderContext. These contexts have a Column, and Column has the ColumnDef again. Through the built declarations, TypeScript measures TValue of Column and HeaderContext as invariant. The result depends on the order of the checks. Thus ColumnDef<…, string> does not fit ColumnDef<…, unknown>, also with the bivarianceHack method syntax on ColumnDefTemplate. out TValue annotations do not help, because TypeScript cannot prove covariance through the generic ExtractFeatureMapTypes. A test that imports src does not show the failure. The type test packages/core/tests/types/columnValueVariance.ts imports @ember-lattice/core, and thus the declarations.

columnHelper.columns already infers one value type for each column (ColumnDefsOf). This ADR is about a raw list without the helper.

Decision drivers

Not recorded in the original ADR.

Options considered

Options

  1. A wrapper type with (props: never) => unknown. A mapped copy of ColumnDef gives each value callback a never input. Each def fits, but an inline cell: ctx => … gets ctx: never (tests/unit/flex-render.test.ts). Also, TypeScript cannot infer TFeatures and TData through the mapped type from a typed list of defs (filterFns.test.ts, columnPinningFeature.utils.test.ts, rowModelSlots.test.ts). Rejected.
  2. A mapped copy with NoInfer. It keeps the contextual types but has no inference of TFeatures and TData from the columns. The same three tests fail. Rejected.
  3. A union of ColumnDef and a mapped copy. ColumnDef gives the inference. But two copies of a callback type in the union are not identical during the inference of a generic constructTable call. Then the inline row => and ctx => callbacks have no contextual type. This occurs also with an identity copy. Rejected.
  4. A brand value type inside ColumnDef. Accepted, see below.

Decision

  1. AnyValue is a brand interface ('~latticeAnyValue'), exported from @ember-lattice/core.
  2. ValueMember<TValue, TMember, TErased> is [TValue] extends [AnyValue] ? TErased : TMember. Each def member that uses TValue goes through it:
    • header, footer, cell, aggregatedCell, spanColumns, spanRows and getAggregationValue: the type for unknown, or CallableFunction.
    • accessorFn: AccessorFn<TData, unknown>.
    • meta and aggregationFn: the type for unknown.
  3. The table columns option and the columns of a group def are ReadonlyArray<ColumnDef<TFeatures, TData, AnyValue>>. The type stays the ColumnDef alias, so TypeScript infers TFeatures and TData from its type arguments.
  4. Each function fits CallableFunction. CallableFunction has no call signature, so an inline callback keeps the contextual type of the unknown form.
  5. TableFeature.getDefaultColumnDef returns ColumnDefBase_All<…, unknown> and has no TValue parameter. With a generic TValue, ValueMember stays deferred, and a default callback loses its contextual type.

Casts

ValueMember stays deferred for a generic TValue. Three casts, each with a comment, close the gap:

  1. constructColumns (coreColumnsFeature.utils.ts) casts each AnyValue def to ColumnDef<…, unknown>. A column reads its values as unknown, as TanStack does with any.
  2. constructColumn casts accessorFn to AccessorFn<TData, TValue>.
  3. column_getAggregationValue casts getAggregationValue to its TValue function type.

Consequences

Consequences and limits

  • For an AnyValue def, a callback member accepts a function of each signature. This is as wide as TanStack's any.
  • [any] extends [AnyValue] is true. Thus ColumnDef<…, any> (the TanStack idiom for a mixed list) gives CellContext<…, unknown>, not CellContext<…, any>. An IsAny guard in ValueMember changes the measured variance of Cell and breaks generic core code (cellSelectionFeature.utils.ts), so there is no guard. Apps do not need any for a mixed list in Lattice.
  • [never] extends [AnyValue] is also true, so ColumnDef<…, never> gets the erased members.
  • An app ColumnMeta augmentation that uses TValue in an input position does not fit the option, because meta uses the type for unknown.
  • The type of TableOptions['columns'] changed. tests/unit/readonlyOptions.test.ts asserts the new type.

Confirmation

Not recorded in the original ADR.

Interview record

Each question of the interview with its answer and its source. A fact from the code or a document, a question that the author did not ask, and an assumption are rows too.

QuestionAnswerSource
Where does the text of this page come from?From the Markdown file docs/adr/0027-column-def-any-value.md at commit 4c77ac4. The text of each section is the text of the Markdown file. A section that the Markdown file does not have says so.Document: docs/adr/0027-column-def-any-value.md

Changelog

DateAuthorChange
2026-12-02Joe GaudetStatus in the Markdown file: accepted, 2026-12-02.
2026-12-03Joe GaudetCommit 7ce4af2: Lattice 1.0 (#1)
2026-12-04Joe Gaudet (agent)Converted from docs/adr/0027-column-def-any-value.md to this page. The text is the text of the Markdown file.

The adr skill of skillsaw wrote this page. The HTML in this file is the source of truth. The diagrams are the Mermaid sources in it.