slackapi / slackapi/node-slack-sdk

Cannot access the user id in the "message_changed" event with TypeScript

Open
#2,026 4 comments 3 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

area:typescript bug enhancement pkg:types semver:major
Dominant language
TypeScript
Stars
3.4k
Forks
688
Avg merge
15h 31m
Merged PRs (30d)
27

Description

Reproducible in:
The Slack SDK version

3.13.1

Node.js runtime version

v16.15.1

OS info

ProductName: macOS
ProductVersion: 12.6.5
BuildVersion: 21G531
Darwin Kernel Version 21.6.0: Thu Mar 9 20:08:59 PST 2023; root:xnu-8020.240.18.700.8~1/RELEASE_X86_64

Steps to reproduce:

The Slack docs say that there should be the message.user key in the message_changed event containing the Slack user id.

The TypeScript interface for the MessageChangedEvent refers to the MessageEvent interface in the message and the previous_message properties that make TypeScript assume that accessing event.message.user is not allowed because not every subtype of the message event contains a user id.

It seems like the reference to the MessageEvent is incorrect because (I suppose) not every message can be edited and moreover it makes the circular dependency in types when the message_changed event can reference to the message_changed event and so on.

Expected result:
  • the message property of the message_changed event has the valid type according to the Slack docs
  • no TypeScript errors when accessing event.message.user for the message_changed event.
Actual result:
TS2339: Property 'user' does not exist on type 'MessageEvent'.

Contributor guide

Open the contributing guide

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.

Research direction

Start in src/types/events/message-events.ts around the MessageChangedEvent definition at line 233, then compare its message and previous_message types with the Slack message_changed event documentation. The work is complete when event.message.user is accepted by TypeScript and the event properties match the documented shape.

Written by the indexing model from the issue text.

Assessment

Tech stack
typescript
Domain
api
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.