Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

types 3.0: discriminated union types where appropriate #1816

Open
filmaj opened this issue Jun 13, 2024 · 0 comments
Open

types 3.0: discriminated union types where appropriate #1816

filmaj opened this issue Jun 13, 2024 · 0 comments
Labels
area:typescript issues that specifically impact using the package from typescript projects auto-triage-skip discussion M-T: An issue where more input is needed to reach a decision pkg:types applies to `@slack/types` semver:major
Milestone

Comments

@filmaj
Copy link
Contributor

filmaj commented Jun 13, 2024

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

➜ ack discrim src
src/message-attachments.ts
4:// TODO: breaking changes, use discriminated union for `fallback`, `text` and `block` properties, maybe LegacyAttachment
7:// also further nested discriminated union types that could be helpful here:

src/block-kit/blocks.ts
250:// TODO: breaking change: use a discriminative union to represent section block using `text` or `fields` but

src/block-kit/block-elements.ts
283:  // TODO: breaking change: use discriminative union and separate types for static select of options vs. option groups
289:  // TODO: breaking change: use discriminative union and separate types for static select of options vs. option groups
297:  // options, whereas the below doesn't. Also use a discriminative union here to separate option vs. option groups
324:  // TODO: breaking change: use discriminative union and separate types for static select of options vs. option groups
330:  // TODO: breaking change: use discriminative union and separate types for static select of options vs. option groups
338:  // options, whereas the below doesn't. Also use a discriminative union here to separate option vs. option groups
399:// TODO: breaking change: maybe can use a discriminative union to differentiate between a multi-select convo element
@filmaj filmaj added semver:major discussion M-T: An issue where more input is needed to reach a decision area:typescript issues that specifically impact using the package from typescript projects pkg:types applies to `@slack/types` auto-triage-skip labels Jun 13, 2024
@filmaj filmaj added this to the types@3.0.0 milestone Jun 13, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area:typescript issues that specifically impact using the package from typescript projects auto-triage-skip discussion M-T: An issue where more input is needed to reach a decision pkg:types applies to `@slack/types` semver:major
Projects
None yet
Development

No branches or pull requests

1 participant