types 3.0: discriminated union types where appropriate

Open
#1,816 0 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

@filmaj is already working on this.

Since Aug 30, 2024.

  • #1911 by @filmaj — open

Assessment

Difficulty
4/5
Estimated time
3-5 days
Newbie friendliness
35/100
Issue type
Refactor
Clarity
Mostly clear
Activity status
Stale
Tech stack
typescript
Domain
api

Research direction

Start with the existing discriminated-union example in packages/web-api/src/types/request/chat.ts and review the linked chat.postMessage API documentation. Identify the remaining Message Attachments usage area and model its constraints with discriminated unions; the issue's checklist is complete when Message Attachments is covered, while Block Kit and Event Payloads are already covered by #1905 and #1904.

Written by the indexing model from the issue text.

Description

area:typescript auto-triage-skip discussion pkg:types semver:major

This issue comes out of #1227 and has one example of the suggestion to use discriminated unions in the draft PR #1228 (in this commit specifically).

Discriminated union types let us more accurately model certain kinds of either/or and hierarchical constraints. This article is one example goes into more detail about what this is and how to use it.

We also already use it extensively in the web-api package to model certain API request parameter constraints. The classic example where discriminated unions are useful within Slack is when modeling the parameters for the chat.postMessage method. This method requires one of text, blocks or attachments to be present - and with a discriminated union we model this constraint accurately!

Discriminated Union Usage Areas

  • Message Attachments
  • Block Kit - covered by #1905
  • Event Payloads - covered by #1904
Dominant language
TypeScript
Stars
3.4k
Forks
693
Avg merge
1d 1h
Merged PRs (30d)
67

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from slackapi/node-slack-sdk

All issues in slackapi/node-slack-sdk

Similar issues

More TypeScript issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.