Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 37 additions & 0 deletions table/src/-private/-type-tests/any-column.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import { headlessTable } from '../../index.ts';

import type { AnyColumn, AnyTable, CellContext } from '../../index.ts';
import type { ComponentLike } from '@glint/template';

interface Person {
name: string;
}
declare const people: Person[];
interface MenuMeta {
hidingDisabled?: boolean;
}

declare const GroupedCell: ComponentLike<
CellContext<Person> & { groupBy: 'day' | 'week' }
>;

const table = headlessTable(
{},
{
columns: () => [
{ key: 'name', Cell: GroupedCell, meta: { hidingDisabled: true } },
],
data: () => people,
},
);

// Code that reads a column, whatever its Cells ask for, and names no args.
function isLocked(column: AnyColumn<Person, MenuMeta>) {
return column.meta?.hidingDisabled ?? false;
}
function columnCount(table: AnyTable<Person, MenuMeta>) {
return table.columns.length;
}

isLocked(table.columns[0]!);
columnCount(table);
32 changes: 32 additions & 0 deletions table/src/-private/any.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import type { Column } from './column.ts';
import type { Table } from './table.ts';

/**
* A column of any table, for code that reads a column without rendering its Cell.
*
* The args of a `Cell` are the args of a function, so a column that carries them
* is not a column that carries none. Code that only reads `key`, `name` or `meta`
* would have to name those args and then ignore them. This says "any args" instead.
*
* ```ts
* function widthOf(column: AnyColumn<Person, ExportMeta>) {
* return column.meta?.width;
* }
* ```
*/
export type AnyColumn<T = unknown, ColumnMeta = unknown> = Column<
T,
ColumnMeta,
any,
any
>;

/**
* A table of any shape, the counterpart of `AnyColumn`.
*/
export type AnyTable<T = unknown, ColumnMeta = unknown> = Table<
T,
ColumnMeta,
any,
any
>;
1 change: 1 addition & 0 deletions table/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ export { deserializeSorts, serializeSorts } from './utils.ts';
* Public Types
*******************************/
export type { Column } from './-private/column.ts';
export type { AnyColumn, AnyTable } from './-private/any.ts';
export type {
CellContext,
ColumnConfig,
Expand Down