-
Notifications
You must be signed in to change notification settings - Fork 5
Add generic type parameters for optional strong typing of Options and Cell component for template type checking #111
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
Introduces OptionsType and CellArgs as generic parameters across the table system to enable type-safe Cell component signatures and custom options in Glint. - Add OptionsType and CellArgs generics to Table, Column, and related classes - Split CellContext into CellConfigContext (optional fields) and CellContext (required fields) - Export CellContext as part of the public API - Update all internal usages to support the new generic parameters
| } & Record<string, unknown>; | ||
|
|
||
| export interface ColumnConfig<T = unknown> { | ||
| export interface ColumnConfig<T = unknown, OptionsType = any, CellArgs = any> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you do knownown, are things able to be inferred (maybe not so explicitly needed?)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes, important question. I see the tests are failing. Will look into it (works on my machine™)
| * a convenience for consumers of the headless table | ||
| */ | ||
| Cell?: ComponentLike<CellContext<T>>; | ||
| Cell?: ComponentLike<CellArgs>; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
T previously allowed for inferred types - does this still work?
# Conflicts: # table/src/-private/column.ts
Summary
OptionsTypeandCellArgs) throughout the table system for improved type safetyCellContextinto two types:CellConfigContext(for configuration) andCellContext(for runtime)CellContextas part of the public APIMotivation
When defining custom Cell components with custom options, there was no way to get proper type safety in Glint. This change allows developers to specify the exact shape of their Cell component arguments and options, enabling full type inference in templates.
Changes
Table,Column,TableConfig,ColumnConfig, andheadlessTablenow acceptOptionsTypeandCellArgsgeneric parametersCellContextsplit into:CellConfigContext<T, OptionsType>: For defining column options (optional fields for user convenience)CellContext<T, OptionsType>: For Cell components (required fields since they're always provided at runtime)CellContextexported from the public API for easier type annotationsExample Usage
Breaking Changes
None - the new generic parameters default to any, maintaining backward compatibility.