Yoctol/bottender

typechecking error slack.event('interactive_message'

dcsan opened this issue · 1 comments

dcsan commented

Describe the bug
typescript typecheck error/warning

    slack.event('interactive_message', Dispatcher.button),

results in:
Argument of type '"interactive_message"' is not assignable to parameter of type 'EventTypes'.

I had a look at the type defs

declare type Slack = Route & {
    any: Route;
    message: Route;
    event: <C extends AnyContext>(eventType: EventTypes, action: Action<SlackContext, any>) => {
        predicate: RoutePredicate<C>;
        action: Action<SlackContext, any>;
    };

EventTypes:

export declare type EventTypes = 'message' | 'app_uninstalled' | 'channel_archive' | 'channel_created' | 'channel_deleted' | 'channel_history_changed' | 'channel_rename' | 'channel_unarchive' | 'dnd_updated' | 'dnd_updated_user' | 'email_domain_changed' | 'emoji_changed' | 'file_change' | 'file_comment_added' | 'file_comment_deleted' | 'file_comment_edited' | 'file_created' | 'file_deleted' | 'file_public' | 'file_shared' | 'file_unshared' | 'grid_migration_finished' | 'grid_migration_started' | 'group_archive' | 'group_close' | 'group_history_changed' | 'group_open' | 'group_rename' | 'group_unarchive' | 'im_close' | 'im_created' | 'im_history_changed' | 'im_open' | 'link_shared' | 'member_joined_channel' | 'member_left_channel' | 'pin_added' | 'pin_removed' | 'reaction_added' | 'reaction_removed' | 'star_added' | 'star_removed' | 'subteam_created' | 'subteam_members_changed' | 'subteam_self_added' | 'subteam_self_removed' | 'subteam_updated' | 'team_domain_change' | 'team_join' | 'team_rename' | 'tokens_revoked' | 'url_verification' | 'user_change';

later you also have

export declare type SlackRawEvent = Message | InteractiveMessageEvent | BlockActionEvent | ViewEvent | CommandEvent;

export declare type InteractiveMessageEvent = UIEvent & {
    type: 'interactive_message';
};

so perhaps... a union type is needed?

eventType: EventTypes | SlackRawEvent

eventType: EventTypes | InteractiveMessageEvent

but I'm not sure if that's putting too many overloads into the method? I'm sure you've partitioned all those events like that for a reason.

or perhaps instead of slack.event(..) there should be a slack.rawEvent( .. ) ?

To Reproduce
try to add the above to a router

Expected behavior
clean type checks

Screenshots

This should be solved by #841, #842.