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

Fix #1472 say argument does not exist for pin_* events in TS #1473

Merged
merged 1 commit into from
Jun 3, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 29 additions & 5 deletions src/types/events/base-events.ts
Original file line number Diff line number Diff line change
Expand Up @@ -585,12 +585,38 @@ export interface MemberLeftChannelEvent {

export type MessageEvent = AllMessageEvents;

export interface PinnedMessageItem {
client_msg_id?: string;
type: string;
app_id?: string;
team?: string;
user: string;
bot_id?: string;
bot_profile?: BotProfile;
text?: string;
attachments?: MessageAttachment[];
blocks?: (KnownBlock | Block)[];
pinned_to?: string[];
permalink: string;
}
export interface PinnedFileItem {
id: string;
// TODO: Add all other possible properties here
}

export interface PinnedItem {
type: string;
channel: string;
created_by: string;
created: number;
message?: PinnedMessageItem;
file?: PinnedFileItem;
}
export interface PinAddedEvent {
type: 'pin_added';
user: string;
channel_id: string;
// TODO: incomplete, should be message | file | file comment (deprecated)
item: Record<string, unknown>;
item: PinnedItem;
item_user: string;
pin_count: string;
pinned_info: {
Expand All @@ -600,13 +626,11 @@ export interface PinAddedEvent {
};
event_ts: string;
}

export interface PinRemovedEvent {
type: 'pin_removed';
user: string;
channel_id: string;
// TODO: incomplete, should be message | file | file comment (deprecated)
item: Record<string, unknown>;
item: PinnedItem;
item_user: string;
pin_count: string;
pinned_info: {
Expand Down
18 changes: 17 additions & 1 deletion types-tests/event.test-d.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { expectNotType, expectType } from 'tsd';
import { App, SlackEvent, AppMentionEvent, ReactionAddedEvent, ReactionRemovedEvent, UserHuddleChangedEvent, UserProfileChangedEvent, UserStatusChangedEvent } from '..';
import { App, SlackEvent, AppMentionEvent, ReactionAddedEvent, ReactionRemovedEvent, UserHuddleChangedEvent, UserProfileChangedEvent, UserStatusChangedEvent, PinAddedEvent, SayFn, PinRemovedEvent } from '..';

const app = new App({ token: 'TOKEN', signingSecret: 'Signing Secret' });

Expand Down Expand Up @@ -50,3 +50,19 @@ expectType<void>(
await Promise.resolve(event);
})
);

expectType<void>(
app.event('pin_added', async ({ say, event }) => {
expectType<SayFn>(say);
expectType<PinAddedEvent>(event);
await Promise.resolve(event);
})
);

expectType<void>(
app.event('pin_removed', async ({ say, event }) => {
expectType<SayFn>(say);
expectType<PinRemovedEvent>(event);
await Promise.resolve(event);
})
);