Skip to content

Commit

Permalink
fix: type narrowing
Browse files Browse the repository at this point in the history
  • Loading branch information
deptyped committed Feb 14, 2023
1 parent 66cb6f3 commit 1e7722b
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 22 deletions.
1 change: 1 addition & 0 deletions src/deps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ export {
type CallbackQueryContext,
type ChatTypeContext,
type Context,
type Filter,
type MiddlewareFn,
} from "https://lib.deno.dev/x/grammy@1.x/mod.ts";

Expand Down
31 changes: 9 additions & 22 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,9 @@ import {
Chat,
ChatMember,
ChatMemberUpdated,
ChatShared,
Context,
Filter,
User,
UserShared,
} from "./deps.ts";

export type MaybePromise<T> = T | Promise<T>;
Expand Down Expand Up @@ -64,30 +63,18 @@ export type ChatMemberContext<

// ctx.msg.user_shared

type UserSharedType = {
msg: {
user_shared: UserShared;
};
message: {
user_shared: UserShared;
};
};

export type UserSharedContext<
C extends Context = Context,
> = C & UserSharedType;
> = Filter<
C,
":user_shared"
>;

// ctx.msg.user_shared

type ChatSharedType = {
msg: {
chat_shared: ChatShared;
};
message: {
chat_shared: ChatShared;
};
};

export type ChatSharedContext<
C extends Context = Context,
> = C & ChatSharedType;
> = Filter<
C,
":chat_shared"
>;

0 comments on commit 1e7722b

Please sign in to comment.