MessageContentUnion is empty
Issue type:
[ ] bug report
Airgram version:
[ ] latest
Hi, looks like message.content type has no properties.
I think this happens because currently it is a union of all possible types.
MessageContentUnion = MessageText | MessageAnimation | MessageAudio...
I think it should be an aggregate of all possible types.
MessageContentUnion = MessageText & MessageAnimation & MessageAudio...
Hello, I believe current behavior is correct. You can use chaining operator to avoid the error. Like:
const text = update.message.content?.text
Nope, looks like there is a problem with types. text property of content should be optional, but it does not exist.
The text property is not optional. Some content types (like messageText) always contain this property, while others never do. Different message types represent by different set of properties and almost all properties are "optional".
You need to check what kind of content you handle to avoid this error:
airgram.on('updateNewMessage', async (ctx) => {
const { message } = ctx.update
if (message.content._ === 'messageText') {
console.log(message.content.text) // no error
}
})
I did exactly what you said, but I still get the error. What version of typescript are you using?
I could make it work with a direct type cast, but it is not very convenient
const content = update.message.content as MessageContent.MessageText
I've tested with Typescript 3.7.5 and 3.9.7.
Can you create a small repository to reproduce this error?