-
Notifications
You must be signed in to change notification settings - Fork 399
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
Typescript missing props on message #861
Comments
Hey @laekem34! We are aware that the current type system is lacking. #832 landed on main and probably helps with this. It will be included in the next release (3.4.0). Essentially it allows you to specify subtypes of messages which then gives the full message props for that type. Let me know if that helps |
Hi @laekem34, thanks for asking this question! Unfortunately, some of the fields in the message payload are not accessible without if/else statements in TypeScript. If you want to handle only newly posted messages, checking if it has no subtype or "bot_message" (if other bot use is a "classic" app, the message events generated by it can be this) should work for you. app.message(async ({ message }) => {
message.channel; // the property access should compile
// The type here is still a union type of all the possible subtyped events.
// Thus, only the fields available for all the types can be resolved outside if/else statements.
expectError(message.user);
if (message.subtype === undefined) {
expectType<GenericMessageEvent>(message);
message.user; // the property access should compile
message.channel; // the property access should compile
message.team; // the property access should compile
}
if (message.subtype === 'bot_message') {
expectType<BotMessageEvent>(message);
message.user; // the property access should compile
message.channel; // the property access should compile
}
}); If you are interested in the complete version of the type tests, check my pull request: |
Hello ! Thank you very much. I was a little confused on how it worked. I understand better now! |
Description
Describe your issue here.
What type of issue is this? (place an
x
in one of the[ ]
)Requirements (place an
x
in each of the[ ]
)Bug Report
Some props are missing with @slack/bolt typescript when using message listener like message.text or message.user or .team
Reproducible in: VS-code
package version: 3.3.0
node version: 15.0.1
OS version(s): window 10
Attachments:
The text was updated successfully, but these errors were encountered: