Add generic type parameters for optional strong typing of Options and Cell component for template type checking#111
Draft
johanrd wants to merge 11 commits intouniversal-ember:mainfrom
Draft
Add generic type parameters for optional strong typing of Options and Cell component for template type checking#111johanrd wants to merge 11 commits intouniversal-ember:mainfrom
johanrd wants to merge 11 commits intouniversal-ember:mainfrom
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> { |
Contributor
There was a problem hiding this comment.
If you do knownown, are things able to be inferred (maybe not so explicitly needed?)
Contributor
Author
There was a problem hiding this comment.
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>; |
Contributor
There was a problem hiding this comment.
T previously allowed for inferred types - does this still work?
# Conflicts: # table/src/-private/column.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.