Skip to content

Commit ee1961f

Browse files
committed
fix TData in custom filterFns
1 parent dcab1c3 commit ee1961f

31 files changed

Lines changed: 452 additions & 197 deletions

File tree

docs/framework/angular/guide/migrating.md

Lines changed: 48 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,18 @@
22
title: Migrating to TanStack Table v9 (Angular)
33
---
44

5+
> [!NOTE]
6+
> `v9.0.0-beta.10` introduces a breaking change in how row models are defined in order to bring increased type-safety features. Row model factories and function registries now live as slots on the `features` object instead of a separate `rowModels` option, and the factories no longer take arguments. If you migrated on an earlier beta, see the [Row Model Factories](#row-model-factories) section below for the new shape.
7+
58
## What's New in TanStack Table v9
69

710
TanStack Table v9 is a major release that introduces significant architectural improvements while maintaining the core table logic you're familiar with. Here are the key changes:
811

9-
### 1. Tree-shaking
12+
### 1. Tree Shaking and Extensibility
1013

1114
- **Features are tree-shakeable**: Features are now treated as plugins: import only what you use. If your table only needs sorting, you won't ship filtering, pagination, or other feature code. Bundlers can eliminate unused code, so for smaller tables you can expect a meaningfully smaller bundle compared to v8. This also lets TanStack Table add features over time without bloating everyone's bundles.
12-
- **Row models and their functions are refactored**: Row model factories (`createFilteredRowModel`, `createSortedRowModel`, etc.) now accept their processing functions (`filterFns`, `sortFns`, `aggregationFns`) as parameters. This enables tree-shaking of the functions themselves: if you use a custom filter, you don't pay for built-in filters you never use.
15+
- **Row models and their functions are refactored**: Row model factories (`createFilteredRowModel`, `createSortedRowModel`, etc.) are now slots on the `features` object, and their processing functions (`filterFns`, `sortFns`, `aggregationFns`) are registered as their own feature slots. This enables tree-shaking of the functions themselves: if you only register a custom filter, you don't pay for built-in filters you never use.
16+
- **Custom feature plugins with full type safety**: The same plugin architecture that powers the built-in features is open to your own code. Write a custom feature with its own state, options, and APIs, register it in `tableFeatures()` alongside the built-ins, and the table's types pick it all up automatically. See the [Custom Features Guide](./custom-features.md).
1317

1418
### 2. State Management
1519

@@ -21,6 +25,12 @@ TanStack Table v9 is a major release that introduces significant architectural i
2125
- **`tableOptions`**: New utilities let you compose and share table configurations. Define `features` (including row model factories) and default options once, then reuse them across tables or pass them through `createTableHook`.
2226
- **`createTableHook`** (optional, advanced): Create reusable, strongly typed Angular table factories with pre-bound features, row models, default options, and component registries.
2327

28+
### 4. Improved Type Safety (No More Declaration Merging)
29+
30+
- **Function registries replace `declare module` augmentation**: Custom filter, sort, and aggregation functions are registered by name in the `filterFns` / `sortFns` / `aggregationFns` slots on `tableFeatures()`. The registered keys become the valid, type-safe string values for `filterFn`, `sortFn`, `globalFilterFn`, and `aggregationFn` in your column definitions, with full inference. No more augmenting the `FilterFns` / `SortFns` / `AggregationFns` interfaces globally.
31+
- **Per-table meta slots**: The type-only `tableMeta`, `columnMeta`, and `filterMeta` slots declare meta types for a single table instead of merging into a global interface. The `filterMeta` slot types both the `addMeta` callback in filter functions and the values read back from `row.columnFiltersMeta`.
32+
- **Feature-gated APIs and validated prerequisites**: APIs like `table.setSorting` only exist on the table type when their feature is registered, and `tableFeatures()` validates slot prerequisites at the type level. Registering `sortFns` without `rowSortingFeature`, or `globalFilteringFeature` without `columnFilteringFeature`, is a typed error instead of a silent runtime no-op.
33+
2434
### The Good News: Most Upgrades Are Opt-in
2535

2636
While v9 is a significant upgrade, **you don't have to adopt everything at once**:
@@ -213,7 +223,7 @@ class TableCmp {
213223
```ts
214224
// v8
215225
import {
216-
injectTable,
226+
createAngularTable,
217227
getCoreRowModel,
218228
getFilteredRowModel,
219229
getSortedRowModel,
@@ -552,7 +562,7 @@ const featureOptions = tableOptions({ features })
552562
```
553563

554564
```ts
555-
import { injectTable, tableOptions, createPaginatedRowModel } from '@tanstack/angular-table'
565+
import { injectTable, tableOptions } from '@tanstack/angular-table'
556566

557567
// Another partial (inherits features from spread)
558568
const paginationDefaults = tableOptions({
@@ -733,6 +743,39 @@ const features = tableFeatures({
733743

734744
See the new [Table and Column Meta Guide](../../../guide/table-and-column-meta) for full details on both approaches.
735745

746+
### `FilterFns`/`SortFns`/`AggregationFns`/`FilterMeta` Augmentation Replaced by Registry Slots
747+
748+
In v8, making a custom function usable as a string reference (like `filterFn: 'fuzzy'`) required `declare module` augmentation of the `FilterFns` interface, and typing filter meta required augmenting `FilterMeta`. In v9, registering the function in the matching registry slot does both jobs with no global augmentation:
749+
750+
```ts
751+
// v8
752+
declare module '@tanstack/angular-table' {
753+
interface FilterFns {
754+
fuzzy: FilterFn<unknown>
755+
}
756+
interface FilterMeta {
757+
itemRank: RankingInfo
758+
}
759+
}
760+
761+
// v9 - register in the slot; the key becomes a valid string value
762+
interface FuzzyFilterMeta {
763+
itemRank?: RankingInfo
764+
}
765+
766+
const features = tableFeatures({
767+
columnFilteringFeature,
768+
filteredRowModel: createFilteredRowModel(),
769+
filterFns: { ...filterFns, fuzzy: fuzzyFilter },
770+
filterMeta: metaHelper<FuzzyFilterMeta>(),
771+
})
772+
773+
// 'fuzzy' now typechecks in column defs for tables using these features
774+
columnHelper.accessor('name', { filterFn: 'fuzzy' })
775+
```
776+
777+
The same pattern applies to `sortFns` (for `sortFn` string values) and `aggregationFns` (for `aggregationFn` string values). See the [Fuzzy Filtering Guide](./fuzzy-filtering.md) for a complete example.
778+
736779
### `RowData` Type Restriction
737780

738781
The `RowData` type is now more restrictive:
@@ -754,6 +797,7 @@ This change improves type safety. If you were passing unusual data types, ensure
754797
- [ ] Update your table setup to v9 and define `features` using `tableFeatures()` (or use `stockFeatures`)
755798
- [ ] Migrate `get*RowModel()` options: move row model factories into `tableFeatures` as named slots
756799
- [ ] Move `filterFns`, `sortFns`, and `aggregationFns` into `tableFeatures` as named slots (no longer passed as factory arguments)
800+
- [ ] Replace `declare module` augmentation of `FilterFns`/`SortFns`/`AggregationFns` with registry-slot registration, and `FilterMeta` augmentation with the `filterMeta` slot
757801
- [ ] Update TypeScript types to include `TFeatures` generic
758802
- [ ] Update state access: `table.getState().slice``table.atoms.<slice>.get()` where possible; use `table.store.get()` for full-state/debug reads
759803
- [ ] Update `createColumnHelper<TData>()``createColumnHelper<TFeatures, TData>()`

docs/framework/lit/guide/migrating.md

Lines changed: 45 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,21 @@
22
title: Migrating to TanStack Table v9 (Lit)
33
---
44

5+
> [!NOTE]
6+
> `v9.0.0-beta.10` introduces a breaking change in how row models are defined in order to bring increased type-safety features. Row model factories and function registries now live as slots on the `features` object instead of a separate `rowModels` option, and the factories no longer take arguments. If you migrated on an earlier beta, see the [Row Model and Function Registry Migration](#row-model-and-function-registry-migration) section below for the new shape.
7+
58
## What's New in TanStack Table v9
69

710
TanStack Table v9 is a major release with explicit feature registration, row model registration, and a new atom-backed state model. The Lit adapter wraps those APIs in a `ReactiveController`.
811

912
> The Lit adapter may change during the v9 beta cycle. This guide documents the current local v9 API and avoids speculating about future beta changes.
1013
11-
### 1. Tree-shaking
14+
### 1. Tree Shaking and Extensibility
1215

1316
- **Features are tree-shakeable**: register only the table features you use.
1417
- **Row models are slots on features**: row model factories and function registries are slots on the `tableFeatures({...})` call instead of a separate `rowModels` option.
1518
- **Function registries are feature slots**: `sortFns`, `filterFns`, and `aggregationFns` are registered on `tableFeatures` alongside the row model factories.
19+
- **Custom feature plugins with full type safety**: The same plugin architecture that powers the built-in features is open to your own code. Write a custom feature with its own state, options, and APIs, register it in `tableFeatures()` alongside the built-ins, and the table's types pick it all up automatically. See the [Custom Features Guide](./custom-features.md).
1620

1721
### 2. State Management
1822

@@ -26,6 +30,12 @@ TanStack Table v9 is a major release with explicit feature registration, row mod
2630
- **`tableOptions()`**: compose reusable option fragments.
2731
- **`createTableHook()`**: define shared Lit table factories with pre-bound features, row models, defaults, and render helpers.
2832

33+
### 4. Improved Type Safety (No More Declaration Merging)
34+
35+
- **Function registries replace `declare module` augmentation**: Custom filter, sort, and aggregation functions are registered by name in the `filterFns` / `sortFns` / `aggregationFns` slots on `tableFeatures()`. The registered keys become the valid, type-safe string values for `filterFn`, `sortFn`, `globalFilterFn`, and `aggregationFn` in your column definitions, with full inference. No more augmenting the `FilterFns` / `SortFns` / `AggregationFns` interfaces globally.
36+
- **Per-table meta slots**: The type-only `tableMeta`, `columnMeta`, and `filterMeta` slots declare meta types for a single table instead of merging into a global interface. The `filterMeta` slot types both the `addMeta` callback in filter functions and the values read back from `row.columnFiltersMeta`.
37+
- **Feature-gated APIs and validated prerequisites**: APIs like `table.setSorting` only exist on the table type when their feature is registered, and `tableFeatures()` validates slot prerequisites at the type level. Registering `sortFns` without `rowSortingFeature`, or `globalFilteringFeature` without `columnFilteringFeature`, is a typed error instead of a silent runtime no-op.
38+
2939
### The Good News: Most Table Logic Is Still Familiar
3040

3141
- Column definitions keep the same basic `accessorKey`, `accessorFn`, `header`, `cell`, and `footer` shapes.
@@ -600,6 +610,39 @@ const features = tableFeatures({
600610

601611
See the new [Table and Column Meta Guide](../../../guide/table-and-column-meta) for full details on both approaches.
602612

613+
### `FilterFns`/`SortFns`/`AggregationFns`/`FilterMeta` Augmentation Replaced by Registry Slots
614+
615+
In v8, making a custom function usable as a string reference (like `filterFn: 'fuzzy'`) required `declare module` augmentation of the `FilterFns` interface, and typing filter meta required augmenting `FilterMeta`. In v9, registering the function in the matching registry slot does both jobs with no global augmentation:
616+
617+
```ts
618+
// v8
619+
declare module '@tanstack/lit-table' {
620+
interface FilterFns {
621+
fuzzy: FilterFn<unknown>
622+
}
623+
interface FilterMeta {
624+
itemRank: RankingInfo
625+
}
626+
}
627+
628+
// v9 - register in the slot; the key becomes a valid string value
629+
interface FuzzyFilterMeta {
630+
itemRank?: RankingInfo
631+
}
632+
633+
const features = tableFeatures({
634+
columnFilteringFeature,
635+
filteredRowModel: createFilteredRowModel(),
636+
filterFns: { ...filterFns, fuzzy: fuzzyFilter },
637+
filterMeta: metaHelper<FuzzyFilterMeta>(),
638+
})
639+
640+
// 'fuzzy' now typechecks in column defs for tables using these features
641+
columnHelper.accessor('name', { filterFn: 'fuzzy' })
642+
```
643+
644+
The same pattern applies to `sortFns` (for `sortFn` string values) and `aggregationFns` (for `aggregationFn` string values). See the [Fuzzy Filtering Guide](./fuzzy-filtering.md) for a complete example.
645+
603646
### `RowData` Type Restriction
604647

605648
Prefer explicit object row types:
@@ -622,6 +665,7 @@ type Person = {
622665
- [ ] Move row model factories and function registries into `tableFeatures({...})` slots (remove the separate `rowModels` option).
623666
- [ ] Remove `getCoreRowModel`; the core row model is automatic.
624667
- [ ] Register `sortFns`, `filterFns`, and `aggregationFns` as slots on `tableFeatures({...})` (not as factory arguments).
668+
- [ ] Replace `declare module` augmentation of `FilterFns`/`SortFns`/`AggregationFns` with registry-slot registration, and `FilterMeta` augmentation with the `filterMeta` slot.
625669
- [ ] Rename `sortingFn` to `sortFn`.
626670
- [ ] Add `typeof features` to column helpers and types.
627671
- [ ] Replace `table.getState()` reads with `table.state`, `table.store.state`, or `table.atoms.<slice>.get()`.

docs/framework/preact/guide/migrating.md

Lines changed: 45 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,19 @@
22
title: Migrating to TanStack Table v9 (Preact)
33
---
44

5+
> [!NOTE]
6+
> `v9.0.0-beta.10` introduces a breaking change in how row models are defined in order to bring increased type-safety features. Row model factories and function registries now live as slots on the `features` object instead of a separate `rowModels` option, and the factories no longer take arguments. If you migrated on an earlier beta, see the [Row Model Factories](#row-model-factories) section below for the new shape.
7+
58
## What's New in TanStack Table v9
69

710
TanStack Table v9 is a major release with a smaller, more explicit table setup. The core table logic is familiar, but the table instance now declares exactly which features, row models, and state subscriptions it needs.
811

9-
### 1. Tree-shaking
12+
### 1. Tree Shaking and Extensibility
1013

1114
- **Features are tree-shakeable**: features are registered explicitly. If a table only needs sorting and pagination, it does not need to ship filtering, grouping, or row selection code.
1215
- **Row models are registered explicitly**: row model factories now live as slots on `tableFeatures({...})` instead of root `get*RowModel` options or a `rowModels` object.
1316
- **Function registries moved to features slots**: `sortFns`, `filterFns`, and `aggregationFns` are registered as slots on `tableFeatures` alongside the row model factories. This lets unused built-in functions tree-shake.
17+
- **Custom feature plugins with full type safety**: The same plugin architecture that powers the built-in features is open to your own code. Write a custom feature with its own state, options, and APIs, register it in `tableFeatures()` alongside the built-ins, and the table's types pick it all up automatically. See the [Custom Features Guide](./custom-features.md).
1418

1519
### 2. State Management
1620

@@ -24,6 +28,12 @@ TanStack Table v9 is a major release with a smaller, more explicit table setup.
2428
- **`tableOptions()`**: build type-safe partial table option objects that can be shared and composed.
2529
- **`createTableHook()`**: create app-level Preact table factories with shared features, row models, defaults, and component conventions.
2630

31+
### 4. Improved Type Safety (No More Declaration Merging)
32+
33+
- **Function registries replace `declare module` augmentation**: Custom filter, sort, and aggregation functions are registered by name in the `filterFns` / `sortFns` / `aggregationFns` slots on `tableFeatures()`. The registered keys become the valid, type-safe string values for `filterFn`, `sortFn`, `globalFilterFn`, and `aggregationFn` in your column definitions, with full inference. No more augmenting the `FilterFns` / `SortFns` / `AggregationFns` interfaces globally.
34+
- **Per-table meta slots**: The type-only `tableMeta`, `columnMeta`, and `filterMeta` slots declare meta types for a single table instead of merging into a global interface. The `filterMeta` slot types both the `addMeta` callback in filter functions and the values read back from `row.columnFiltersMeta`.
35+
- **Feature-gated APIs and validated prerequisites**: APIs like `table.setSorting` only exist on the table type when their feature is registered, and `tableFeatures()` validates slot prerequisites at the type level. Registering `sortFns` without `rowSortingFeature`, or `globalFilteringFeature` without `columnFilteringFeature`, is a typed error instead of a silent runtime no-op.
36+
2737
### The Good News: Most Upgrades Are Opt-in
2838

2939
- You can start with `stockFeatures` while migrating, then replace it with explicit feature registration.
@@ -588,6 +598,39 @@ const features = tableFeatures({
588598

589599
See the new [Table and Column Meta Guide](../../../guide/table-and-column-meta) for full details on both approaches.
590600

601+
### `FilterFns`/`SortFns`/`AggregationFns`/`FilterMeta` Augmentation Replaced by Registry Slots
602+
603+
In v8, making a custom function usable as a string reference (like `filterFn: 'fuzzy'`) required `declare module` augmentation of the `FilterFns` interface, and typing filter meta required augmenting `FilterMeta`. In v9, registering the function in the matching registry slot does both jobs with no global augmentation:
604+
605+
```tsx
606+
// v8 / before: React adapter through preact/compat
607+
declare module '@tanstack/react-table' {
608+
interface FilterFns {
609+
fuzzy: FilterFn<unknown>
610+
}
611+
interface FilterMeta {
612+
itemRank: RankingInfo
613+
}
614+
}
615+
616+
// v9 - register in the slot; the key becomes a valid string value
617+
interface FuzzyFilterMeta {
618+
itemRank?: RankingInfo
619+
}
620+
621+
const features = tableFeatures({
622+
columnFilteringFeature,
623+
filteredRowModel: createFilteredRowModel(),
624+
filterFns: { ...filterFns, fuzzy: fuzzyFilter },
625+
filterMeta: metaHelper<FuzzyFilterMeta>(),
626+
})
627+
628+
// 'fuzzy' now typechecks in column defs for tables using these features
629+
columnHelper.accessor('name', { filterFn: 'fuzzy' })
630+
```
631+
632+
The same pattern applies to `sortFns` (for `sortFn` string values) and `aggregationFns` (for `aggregationFn` string values). See the [Fuzzy Filtering Guide](./fuzzy-filtering.md) for a complete example.
633+
591634
### `RowData` Type Restriction
592635

593636
`RowData` is now constrained to record-like objects or arrays. Prefer object row types such as:
@@ -607,7 +650,7 @@ type Person = {
607650
- [ ] Replace `@tanstack/react-table` imports used through `preact/compat` with `@tanstack/preact-table`.
608651
- [ ] Replace `useReactTable` with `useTable`.
609652
- [ ] Define `features` using `tableFeatures()` (or use `stockFeatures`).
610-
- [ ] Move row model factories from `rowModels: {...}` into `tableFeatures({...})` slots.
653+
- [ ] Migrate `get*RowModel()` options (or earlier-beta `rowModels: {...}` entries) to `tableFeatures({...})` slots (e.g. `filteredRowModel: createFilteredRowModel()`).
611654
- [ ] Drop `getCoreRowModel`; the core row model is automatic.
612655
- [ ] Move `sortingFns`, `filterFns`, and `aggregationFns` into `tableFeatures` slots (not factory args).
613656
- [ ] Rename `sortingFn` to `sortFn` and `sortingFns` to `sortFns`.

0 commit comments

Comments
 (0)