diff --git a/.changeset/table-raw-number-cell.md b/.changeset/table-raw-number-cell.md new file mode 100644 index 000000000..e59e3d0fe --- /dev/null +++ b/.changeset/table-raw-number-cell.md @@ -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`) diff --git a/packages/types/src/block-kit/blocks.ts b/packages/types/src/block-kit/blocks.ts index 20cd9561c..aa9d44d76 100644 --- a/packages/types/src/block-kit/blocks.ts +++ b/packages/types/src/block-kit/blocks.ts @@ -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. */ diff --git a/packages/types/test/blocks.test-d.ts b/packages/types/test/blocks.test-d.ts index 421941b23..59de4897d 100644 --- a/packages/types/test/blocks.test-d.ts +++ b/packages/types/test/blocks.test-d.ts @@ -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 @@ -152,3 +160,32 @@ expectAssignable({ caption: 'A minimal table', rows: [[{ type: 'raw_text', text: 'Header' }], [{ type: 'raw_text', text: 'Value' }]], }); + +// TableBlock +// -- sad path +expectError({}); // missing type and rows +expectError({ type: 'table' }); // missing required rows +// -- happy path +// Table cells can be rich_text, raw_text, or raw_number; column_settings describe column behavior. +expectAssignable({ + 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({ + type: 'table', + rows: [[{ type: 'raw_number', value: 1, text: '1' }]], +}); diff --git a/packages/types/test/composition-objects.test-d.ts b/packages/types/test/composition-objects.test-d.ts new file mode 100644 index 000000000..98a03259b --- /dev/null +++ b/packages/types/test/composition-objects.test-d.ts @@ -0,0 +1,19 @@ +import { expectAssignable, expectError } from 'tsd'; +import type { RawNumberElement, RawTextElement } from '../src/index'; + +// RawNumberElement +// -- sad path +expectError({}); // missing type, value, and text +expectError({ type: 'raw_number' }); // missing required value and text +expectError({ type: 'raw_number', value: 42 }); // missing required text +expectError({ type: 'raw_number', text: '42' }); // missing required value +expectError({ type: 'raw_number', value: '42', text: '42' }); // value must be a number +// -- happy path +expectAssignable({ type: 'raw_number', value: 42, text: '42' }); + +// RawTextElement +// -- sad path +expectError({}); // missing type and text +expectError({ type: 'raw_text' }); // missing required text +// -- happy path +expectAssignable({ type: 'raw_text', text: 'Item' });