|
| 1 | +# AGENTS.md — @slack/types |
| 2 | + |
| 3 | +Instructions for AI coding agents working on this package. |
| 4 | + |
| 5 | +## Package Overview |
| 6 | + |
| 7 | +Shared TypeScript type definitions for the Slack platform. Provides Block Kit elements, composition objects, event types, views, message attachments, message metadata, chunk types, and other common structures used across `@slack/*` packages. |
| 8 | + |
| 9 | +## Architecture |
| 10 | + |
| 11 | +### Source Layout |
| 12 | + |
| 13 | +```txt |
| 14 | +src/ |
| 15 | +├── block-kit/ # Block Kit UI framework types |
| 16 | +│ ├── block-elements.ts # Interactive elements (buttons, menus, inputs, etc.) |
| 17 | +│ ├── blocks.ts # Layout blocks (section, actions, context, etc.) |
| 18 | +│ ├── composition-objects.ts # Text objects, option objects, filter objects, etc. |
| 19 | +│ └── extensions.ts # Extended block types (e.g., for messages, modals) |
| 20 | +├── common/ # Shared small types |
| 21 | +│ ├── bot-profile.ts # Bot profile structure |
| 22 | +│ └── status-emoji-display-info.ts |
| 23 | +├── events/ # Slack event type definitions |
| 24 | +│ ├── index.ts # Barrel export for all event types |
| 25 | +│ └── *.ts # One file per event category (message, channel, user, etc.) |
| 26 | +├── calls.ts # Slack Calls types |
| 27 | +├── chunk.ts # Streaming chunk types |
| 28 | +├── dialog.ts # Legacy dialog types |
| 29 | +├── message-attachments.ts # Message attachment types |
| 30 | +├── message-metadata.ts # Message metadata types |
| 31 | +├── views.ts # Modal and Home tab view types |
| 32 | +└── index.ts # Root barrel export |
| 33 | +``` |
| 34 | + |
| 35 | +### Key Design Principles |
| 36 | + |
| 37 | +- **Pure types** — this package contains only TypeScript type definitions (interfaces, type aliases, enums). No runtime code. |
| 38 | +- **Barrel exports** — `src/index.ts` re-exports everything. Consumers import directly from `@slack/types`. |
| 39 | +- **Discriminated unions** — Block Kit types use discriminated unions keyed on `type` (e.g., `KnownBlock`, `BlockElement`). |
| 40 | + |
| 41 | +## Critical Rules |
| 42 | + |
| 43 | +1. **All types are manually maintained** — there is no code generation in this package. |
| 44 | +2. **Export everything from `src/index.ts`** — every public type must be reachable from the barrel. |
| 45 | +3. **No runtime code** — this package must only contain type definitions, no JavaScript logic. |
| 46 | + |
| 47 | +## Naming Conventions |
| 48 | + |
| 49 | +- **Types/Interfaces**: PascalCase |
| 50 | +- **Block types**: `{Kind}Block` (e.g., `SectionBlock`, `ActionsBlock`) |
| 51 | +- **Element types**: `{Kind}Element` or `{Kind}Action` (e.g., `ButtonElement`, `StaticSelectAction`) |
| 52 | +- **Event types**: `{Category}{Action}Event` (e.g., `MessageChangedEvent`, `ChannelCreatedEvent`) |
| 53 | +- **Composition objects**: descriptive PascalCase (e.g., `PlainTextElement`, `MrkdwnElement`, `Option`, `ConfirmationDialog`) |
| 54 | + |
| 55 | +## Adding New Types |
| 56 | + |
| 57 | +### Adding a New Block Kit Element |
| 58 | + |
| 59 | +1. Add the interface to the appropriate file in `src/block-kit/`: |
| 60 | + - **Layout blocks** → `blocks.ts` |
| 61 | + - **Interactive elements** → `block-elements.ts` |
| 62 | + - **Composition objects** → `composition-objects.ts` |
| 63 | + - **Message/modal extensions** → `extensions.ts` |
| 64 | +2. Add the new type to the relevant discriminated union (e.g., `KnownBlock`, `BlockElement`). |
| 65 | +3. Verify it is exported through `src/index.ts` (already covered if the file is re-exported). |
| 66 | + |
| 67 | +### Adding a New Event Type |
| 68 | + |
| 69 | +1. Find or create the appropriate category file in `src/events/` (e.g., `channel.ts`, `message.ts`). |
| 70 | +2. Define the event interface following existing patterns in that file. |
| 71 | +3. Export the new type from `src/events/index.ts`. |
| 72 | + |
| 73 | +### Adding a New Top-Level Type Category |
| 74 | + |
| 75 | +1. Create a new `.ts` file in `src/`. |
| 76 | +2. Add the `export * from './<filename>'` line to `src/index.ts`. |
| 77 | + |
| 78 | +## Testing |
| 79 | + |
| 80 | +```bash |
| 81 | +npm test --workspace=packages/types # build + type tests |
| 82 | +npm run test:types --workspace=packages/types # tsd only |
| 83 | +``` |
| 84 | + |
| 85 | +- **Test framework**: tsd (type-level testing only) |
| 86 | +- **Test files**: `test/*.test-d.ts` |
| 87 | +- **No unit tests** — since there is no runtime code, only type-level tests are needed. |
| 88 | + |
| 89 | +Use `expectType`, `expectAssignable`, `expectError`, and `expectNotAssignable` from tsd to validate type correctness. |
| 90 | + |
| 91 | +## Common Pitfalls |
| 92 | + |
| 93 | +- **Discriminated union membership** — when adding a new block or element type, forgetting to add it to the union type (e.g., `KnownBlock`) means it won't be recognized in typed arrays like `KnownBlock[]`. |
| 94 | +- **Downstream impact** — types defined here are consumed by `@slack/web-api`, `@slack/webhook`, `@slack/socket-mode`, and other packages. Breaking changes require coordination. |
| 95 | +- **Optional vs. required fields** — match the Slack API documentation. Fields that are always present in API responses should be required; fields that are conditionally present should be optional. |
0 commit comments