diff --git a/docs-app/src/templates/1-get-started/typing-meta-and-cells.gjs.md b/docs-app/src/templates/1-get-started/typing-meta-and-cells.gjs.md index f086ec3..302ed89 100644 --- a/docs-app/src/templates/1-get-started/typing-meta-and-cells.gjs.md +++ b/docs-app/src/templates/1-get-started/typing-meta-and-cells.gjs.md @@ -224,6 +224,20 @@ columns: () => [ `column.getOptionsForRow` has the type of the `@options` that the Cells ask for, and the `defaultValue`. +TypeScript checks each column that you write in place: +a column whose Cell asks for `@options` must have an `options` that returns them. + +```ts +columns: () => [ + // error: `unit` is not a number + { key: "age", Cell: UnitCell, options: () => ({ unit: 3 }) }, + // error: the Cell asks for `@options`, and this column has no `options` + { key: "height", Cell: UnitCell }, +], +``` + +To name the types of options in your own code, import `CellOptions` (what `options` returns) and `CellOptionsOf` (the `@options` of a Cell's args). + ## Code that takes any table A function that accepts `Column` or `Table` accepts columns and tables with any meta and any cell args. @@ -237,6 +251,24 @@ function exportWidthOf(column: Column) { } ``` +## Shared table components + +A component that takes a column list from its caller and builds the table itself +can pass its type arguments through. +The table keeps the cell args, and the column metas, that the list declares: + +```ts +import type { ColumnConfig } from "@universal-ember/table"; + +function makeTable( + parent: object, + columns: ColumnConfig[], + data: Row[], +) { + return headlessTable(parent, { columns: () => columns, data: () => data }); +} +``` + ## Limits - In `value` and `options`, `column.meta` is `unknown`, because TypeScript cannot give it the inferred type there. @@ -244,5 +276,4 @@ function exportWidthOf(column: Column) { - An inline `