Skip to content

Commit

Permalink
Fix #1472 say argument does not exist for pin_* events in TS (#1473)
Browse files Browse the repository at this point in the history
  • Loading branch information
seratch committed Jun 3, 2022
1 parent 23cc0e1 commit 41f0255
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 6 deletions.
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);
})
);

0 comments on commit 41f0255

Please sign in to comment.