diff --git a/types-tests/message.test-d.ts b/types-tests/message.test-d.ts index f1eb598b8..bfcd10820 100644 --- a/types-tests/message.test-d.ts +++ b/types-tests/message.test-d.ts @@ -1,83 +1,98 @@ -import { expectNotType, expectType, expectError } from "tsd"; -import App from "../src/App"; -import type { - MessageEvent, - GenericMessageEvent, - BotMessageEvent, - MessageRepliedEvent, - MeMessageEvent, - MessageDeletedEvent, - ThreadBroadcastMessageEvent, - MessageChangedEvent, - EKMAccessDeniedMessageEvent, -} from ".."; +import { expectNotType, expectType, expectError } from 'tsd'; +// eslint-disable-next-line +import App from '../src/App'; +import { + type MessageEvent, + type GenericMessageEvent, + type BotMessageEvent, + type MessageRepliedEvent, + type MeMessageEvent, + type MessageDeletedEvent, + type ThreadBroadcastMessageEvent, + type MessageChangedEvent, + type EKMAccessDeniedMessageEvent, + AllMessageEvents, +} from '..'; -const app = new App({ token: "TOKEN", signingSecret: "Signing Secret" }); +const app = new App({ token: 'TOKEN', signingSecret: 'Signing Secret' }); // TODO: Resolve the event type when having subtype in a listener constraint // app.message({pattern: 'foo', subtype: 'message_replied'}, async ({ message }) => {}); +// TODO: asserting on the types of event sub-properties is a responsibility of the `@slack/types` package, not bolt. +// e.g. message.user, message.team, etc. // Types for generic message listeners, i.e. MessageEvent aka GenericMessageEvent app.message(async ({ message }) => { expectType(message); - message.channel; // the property access should compile - + expectType(message.channel); // 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); + // TODO: what if subtype is not on the message at all? e.g. !('subtype' in message) if (message.subtype === undefined) { expectType(message); expectNotType(message); + // TODO: move these assertions to `@slack/types` expectType(message.user); - expectType(message.channel); // the property access should compile - message.team; // the property access should compile + expectType(message.channel); + // TODO: should this be potentially undefined? Not all of the various Message event subtype interfaces + // (in @slack/types) have a `team` property - is that correct? Also the GenericMessageEvent has team as optional. + expectType(message.team); } - if (message.subtype === "bot_message") { + if (message.subtype === 'bot_message') { expectType(message); expectNotType(message); - message.user; // the property access should compile - message.channel; // the property access should compile + // TODO: move these assertions to `@slack/types` + // TODO: should this be potentially undefined? + expectType(message.user); + expectType(message.channel); } - if (message.subtype === "ekm_access_denied") { + if (message.subtype === 'ekm_access_denied') { expectType(message); expectNotType(message); - message.user; // the property access should compile - message.channel; // the property access should compile + // TODO: move these assertions to `@slack/types` + expectType(message.channel); } - if (message.subtype === "me_message") { + if (message.subtype === 'me_message') { expectType(message); expectNotType(message); - message.user; // the property access should compile - message.channel; // the property access should compile + // TODO: move these assertions to `@slack/types` + expectType(message.user); + expectType(message.channel); } - if (message.subtype === "message_replied") { + if (message.subtype === 'message_replied') { expectType(message); expectNotType(message); - message.channel; // the property access should compile - message.message; // the property access should compile - message.message.thread_ts; + // TODO: move these assertions to `@slack/types` + expectType(message.channel); + expectType(message.message.thread_ts); } - if (message.subtype === "message_changed") { + if (message.subtype === 'message_changed') { expectType(message); expectNotType(message); - message.channel; // the property access should compile - message.message; // the property access should compile + // TODO: move these assertions to `@slack/types` + expectType(message.channel); + expectType(message.message); } - if (message.subtype === "message_deleted") { + if (message.subtype === 'message_deleted') { expectType(message); expectNotType(message); - message.channel; // the property access should compile - message.ts; // the property access should compile + // TODO: move these assertions to `@slack/types` + expectType(message.channel); + expectType(message.ts); } - if (message.subtype === "thread_broadcast") { + if (message.subtype === 'thread_broadcast') { expectType(message); expectNotType(message); - message.channel; // the property access should compile - message.thread_ts; // the property access should compile - message.ts; // the property access should compile - message.root; // the property access should compile + // TODO: move these assertions to `@slack/types` + expectType(message.channel); + // TODO: this being potentially undefined seems wrong! + expectType(message.thread_ts); + expectType(message.ts); + // TODO: the actual type here seems wrong... + expectNotType(message.root); } await Promise.resolve(message);