Repository navigation
tableMeta / columnMeta slots can't see the table's TData
#6646
Unanswered
tomerzcod7
asked this question in
Ideas
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
We moved our app to v9 and every table goes through one
createTableHook. The tables have different row types, and most of them want the same thing from table meta: anonRowClick(row)with the row typed for that table.The
tableMetaslot from #6316 looked like the right place for it. Thanks for that one, it's been asked for since #4220, #4646 and #4739. What I can't figure out is how to write the slot so it knows which table it ends up on:The slot type is fixed when
tableFeatures()runs andExtractTableMetareturns it as is, so nothing fits in???.RowDatameans every handler casts beforerow.original.namecompiles.anyletsrow.original.nmaethrough. AndPersonties the features object to the people table, which defeats the shared hook.For now we fall back to v8-style declaration merging, since the global
TableMetadoes getTData:That works, but it's global, so every table in the project gets these keys, and the meta guide recommends the slots over it anyway.
ColumnMetahas hadTDataandTValuesince #4145 / #4208, which leaves the slots as the one place you can't reach them.What I'd propose is letting a slot optionally be a type-level function that the library applies to each table's
TData. With thethis-typed interface pattern it's a few lines in table-core, and no public type gets a new generic:Plain object slots resolve exactly like they do today. In an app it looks like this:
Reading it back works too.
table.options.meta?.onRowClick?.(row)is typed with that table'sRow<typeof features, Person>.columnMetacould do the same withTDataandTValue, which gets you things like a per-column formatter typed by the accessor's value:I tried all of this against 9.3.1's published types, with
ExtractTableMetaandExtractColumnMetapatched in a local copy, going throughcreateTableHook,useAppTableandcreateAppColumnHelperon TS 5.9 and 7.0. Correct handlers compile, typos and wrong row types are errors,columnHelper.columns([...])still takes the columns, and plain object slots behave as before. The slots are already type-only, so nothing changes at runtime.I'm not sure how you feel about a
this-typed interface in the public API, and I'm open to a different encoding if you'd rather. The check is also structural, so an object slot that happens to have both aTDataand ametakey would be read as a function. A brandedunique symbolkey would avoid that if you prefer it.If the direction works for you, I'm happy to open a PR with the types, type tests next to
tests/unit/core/table/metaTypeSlots.test.ts, and a short section in the meta guide.All reactions