Skip to content

Commit

Permalink
test: add test for type inference
Browse files Browse the repository at this point in the history
  • Loading branch information
KnorpelSenf committed Apr 1, 2024
1 parent 42c4b92 commit f6c7aa9
Showing 1 changed file with 22 additions and 1 deletion.
23 changes: 22 additions & 1 deletion test/filter.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { type Context, type FilterQuery, matchFilter } from "../src/mod.ts";
import { Context, type FilterQuery, matchFilter } from "../src/mod.ts";
import { assert, assertThrows, describe, it } from "./deps.test.ts";

describe("matchFilter", () => {
Expand Down Expand Up @@ -112,4 +112,25 @@ describe("matchFilter", () => {
);
}
});

it("should work with correct type-inference", () => {
const ctx = new Context(
// deno-lint-ignore no-explicit-any
{ update: { message: { text: "" } } } as any,
// deno-lint-ignore no-explicit-any
undefined as any,
// deno-lint-ignore no-explicit-any
undefined as any,
);
const pred = matchFilter([":text", "callback_query:data"]);
if (pred(ctx)) {
if (ctx.callbackQuery) {
const s: string = ctx.update.callback_query.data;
assert(s);
} else {
const t: string = (ctx.message ?? ctx.channelPost).text;
assert(t);
}
}
});
});

0 comments on commit f6c7aa9

Please sign in to comment.