refactor(table): preserve generic typing across forwardRef export#4
Conversation
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 9274f38602
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| export interface TableColumn<T, K extends TableKey<T> = TableKey<T>> { | ||
| key: K |
There was a problem hiding this comment.
Restore support for non-data display columns
Narrowing TableColumn.key to K extends Extract<keyof T, string> turns a previously supported pattern into a compile-time error: columns used only for UI actions (for example { key: 'actions', render: (...) => ... }) no longer type-check unless 'actions' exists on every row type. The previous API explicitly allowed keyof T | string, and the runtime logic still renders such columns, so this is a source-compatible regression for existing consumers upgrading the library.
Useful? React with 👍 / 👎.
Motivation
Tablecomponent preserves generics across theforwardRefboundary so consumers can write<Table<User>>and get correct compile-time inference forcolumns,rowKey,sorter, andrender.as-based indexing patterns with safer generic indexing so column keys, renderers and filters receive preciseT[K]-typed values.Description
TableInner<T extends Record<string, unknown>>and export a typed wrapper viaexport const Table = forwardRef(TableInner) as TableComponentto preserve external generic inference in JSX. (file:packages/ui/src/components/data/Table.tsx)type TableKey<T> = Extract<keyof T, string>and changedTableColumntoTableColumn<T, K extends TableKey<T> = TableKey<T>>sokey: Kandrenderreceivesvalue: T[K]for accurate typing.record[column.key as keyof typeof record]withrecord[column.key]and updated filtering/sorting state toTableKey<T>-based types (sortKey,filterMap,visibleMap).sorterbefore invocation to avoid optional invocation errors and adjusted React import types for stronger typing.Testing
npm run typecheck:uiand it completed successfully.Codex Task