Skip to content

TableBlock: typed model classes for cells and column_settings instead of Dict[str, Any] #1938

Description

@zimeg

Summary

TableBlock.rows is typed as Sequence[Sequence[Dict[str, Any]]] and column_settings as Optional[Sequence[Optional[Dict[str, Any]]]]. These could be typed model classes instead, similar to how other blocks use composition objects.

Feature request

Table cells — each cell is one of:

  • raw_text: {"type": "raw_text", "text": "..."}
  • rich_text: {"type": "rich_text", "elements": [...]}
  • raw_number: {"type": "raw_number", "value": <number>, "text": "..."} (documented at docs.slack.dev/reference/block-kit/blocks/table-block, though client rendering support is unconfirmed)

These could be modeled as distinct classes (e.g. RawTextCell, RichTextCell) or accepted as a Union type, giving developers autocomplete and type checking instead of hand-building dicts.

Column settings — each entry has typed fields (align: "left" | "center" | "right", is_wrapped: bool) that would benefit from a model class with validation.

Current behavior

block = TableBlock(
    rows=[
        [{"type": "raw_text", "text": "Header"}],  # no type help
        [{"type": "raw_text", "txt": "typo"}],      # no validation
    ],
    column_settings=[{"align": "right", "is_wrapped": True}],  # untyped
)

Expected behavior

block = TableBlock(
    rows=[
        [RawTextCell(text="Header")],       # typed, validated
        [RichTextCell(elements=[...])],     # autocomplete on elements
    ],
    column_settings=[ColumnSettings(align="right", is_wrapped=True)],
)

Dicts should still be accepted for backwards compatibility (Union with dict).

Reference

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions