-
Notifications
You must be signed in to change notification settings - Fork 0
/
typeGuards.ts
31 lines (25 loc) · 1.17 KB
/
typeGuards.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
// --------------------
// Type Guards
// --------------------
import { MessageOriginChannel, MessageOriginChat, MessageOriginHiddenUser, MessageOriginUser } from "https://deno.land/x/[email protected]/mod.ts";
import { AnyMessageOrigin, MessageOriginUnknown } from "./types.ts";
// Type guard for MessageOriginUser
export function isMessageOriginUser(origin: AnyMessageOrigin): origin is MessageOriginUser {
return origin.type === "user";
}
// Type guard for MessageOriginHiddenUser
export function isMessageOriginHiddenUser(origin: AnyMessageOrigin): origin is MessageOriginHiddenUser {
return origin.type === "hidden_user";
}
// Type guard for MessageOriginChat
export function isMessageOriginChat(origin: AnyMessageOrigin): origin is MessageOriginChat {
return origin.type === "chat";
}
// Type guard for MessageOriginChannel
export function isMessageOriginChannel(origin: AnyMessageOrigin): origin is MessageOriginChannel {
return origin.type === "channel";
}
// Type guard for MessageOriginUnknown
export function isMessageOriginUnknown(origin: AnyMessageOrigin): origin is MessageOriginUnknown {
return !["user", "hidden_user", "chat", "channel"].includes(origin.type);
}