diff --git a/deno.jsonc b/deno.jsonc index 4d7e63c..1c52380 100644 --- a/deno.jsonc +++ b/deno.jsonc @@ -4,6 +4,11 @@ "compilerOptions": { "exactOptionalPropertyTypes": true }, + "lint": { + "rules": { + "exclude": ["no-import-prefix"] + } + }, "exports": { ".": "./mod.ts", "./as": "./as/mod.ts", diff --git a/is/literal_one_of.ts b/is/literal_one_of.ts index 42bb0f2..7596a21 100644 --- a/is/literal_one_of.ts +++ b/is/literal_one_of.ts @@ -12,14 +12,14 @@ import type { Predicate, Primitive } from "../type.ts"; * ```ts * import { is } from "@core/unknownutil"; * - * const isMyType = is.LiteralOneOf(["hello", "world"] as const); + * const isMyType = is.LiteralOneOf(["hello", "world"]); * const a: unknown = "hello"; * if (isMyType(a)) { * const _: "hello" | "world" = a; * } * ``` */ -export function isLiteralOneOf( +export function isLiteralOneOf( literals: T, ): Predicate { const s = new Set(literals); diff --git a/is/literal_one_of_test.ts b/is/literal_one_of_test.ts index 23ee172..75e1ef8 100644 --- a/is/literal_one_of_test.ts +++ b/is/literal_one_of_test.ts @@ -28,4 +28,16 @@ Deno.test("isLiteralOneOf", async (t) => { assertType>(true); } }); + + await t.step("works without as const assertion", () => { + const predicate = isLiteralOneOf(["foo", "bar"]); + assertEquals(predicate("foo"), true); + assertEquals(predicate("bar"), true); + assertEquals(predicate("baz"), false); + + const b: unknown = "foo"; + if (predicate(b)) { + assertType>(true); + } + }); });