Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/table-raw-number-cell.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@slack/types": minor
---

feat: allow `raw_number` cells in [`TableBlock`](https://docs.slack.dev/reference/block-kit/blocks/table-block) rows (adds `RawNumberElement`)
4 changes: 2 additions & 2 deletions packages/types/src/block-kit/blocks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -549,9 +549,9 @@ export interface TableBlock extends Block {
*/
type: 'table';
/**
* @description An array consisting of table rows. Maximum 100 rows. Each row object is an array with a max of 20 table cells. Table cells can have a type of raw_text or rich_text.
* @description An array consisting of table rows. Maximum 100 rows. Each row object is an array with a max of 20 table cells. Table cells can have a type of rich_text, raw_text, or raw_number.
*/
rows: (RichTextBlock | RawTextElement)[][];
rows: (RichTextBlock | RawTextElement | RawNumberElement)[][];
/**
* @description An array describing column behavior. If there are fewer items in the column_settings array than there are columns in the table, then the items in the the column_settings array will describe the same number of columns in the table as there are in the array itself. Any additional columns will have the default behavior. Maximum 20 items.
*/
Expand Down
39 changes: 38 additions & 1 deletion packages/types/test/blocks.test-d.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
import { expectAssignable, expectError } from 'tsd';
import type { AlertBlock, CardBlock, CarouselBlock, ContainerBlock, DataTableBlock, KnownBlock } from '../src/index';
import type {
AlertBlock,
CardBlock,
CarouselBlock,
ContainerBlock,
DataTableBlock,
KnownBlock,
TableBlock,
} from '../src/index';

// CardBlock
// -- sad path
Expand Down Expand Up @@ -152,3 +160,32 @@ expectAssignable<KnownBlock>({
caption: 'A minimal table',
rows: [[{ type: 'raw_text', text: 'Header' }], [{ type: 'raw_text', text: 'Value' }]],
});

// TableBlock
// -- sad path
expectError<TableBlock>({}); // missing type and rows
expectError<TableBlock>({ type: 'table' }); // missing required rows
// -- happy path
// Table cells can be rich_text, raw_text, or raw_number; column_settings describe column behavior.
expectAssignable<TableBlock>({
type: 'table',
column_settings: [{ is_wrapped: true }, { align: 'right' }],
rows: [
[
{ type: 'raw_text', text: 'Item' },
{ type: 'raw_text', text: 'Count' },
],
[
{ type: 'raw_text', text: 'Widgets' },
{ type: 'raw_number', value: 42, text: '42' },
],
[
{ type: 'rich_text', elements: [{ type: 'rich_text_section', elements: [{ type: 'text', text: 'Gadgets' }] }] },
{ type: 'raw_number', value: 7, text: '7' },
],
],
});
expectAssignable<KnownBlock>({
type: 'table',
rows: [[{ type: 'raw_number', value: 1, text: '1' }]],
});
19 changes: 19 additions & 0 deletions packages/types/test/composition-objects.test-d.ts

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧪 note: This path is adjacent to similar files including:

  • blocks.test-d.ts
  • block-elements.test-d.ts

And I think we might move these to a separate path similar to how "events" are grouped in a follow up PR!

Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { expectAssignable, expectError } from 'tsd';
import type { RawNumberElement, RawTextElement } from '../src/index';

// RawNumberElement
// -- sad path
expectError<RawNumberElement>({}); // missing type, value, and text
expectError<RawNumberElement>({ type: 'raw_number' }); // missing required value and text
expectError<RawNumberElement>({ type: 'raw_number', value: 42 }); // missing required text
expectError<RawNumberElement>({ type: 'raw_number', text: '42' }); // missing required value
expectError<RawNumberElement>({ type: 'raw_number', value: '42', text: '42' }); // value must be a number
// -- happy path
expectAssignable<RawNumberElement>({ type: 'raw_number', value: 42, text: '42' });

// RawTextElement
// -- sad path
expectError<RawTextElement>({}); // missing type and text
expectError<RawTextElement>({ type: 'raw_text' }); // missing required text
// -- happy path
expectAssignable<RawTextElement>({ type: 'raw_text', text: 'Item' });