Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions deno.jsonc
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@
"compilerOptions": {
"exactOptionalPropertyTypes": true
},
"lint": {
"rules": {
"exclude": ["no-import-prefix"]
}
},
Comment on lines +9 to +11
Copy link

Copilot AI Nov 28, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This lint configuration change appears unrelated to the PR's main purpose of adding a const type parameter to isLiteralOneOf. The entire codebase already uses relative imports (e.g., "../_funcutil.ts", "./literal_one_of.ts"), so if no-import-prefix was actually causing issues, it would affect many files.

Consider removing this unrelated change from the PR, or if it's needed, explain why in the PR description and potentially submit it as a separate change.

Suggested change
"exclude": ["no-import-prefix"]
}
},
}
},
},

Copilot uses AI. Check for mistakes.
"exports": {
".": "./mod.ts",
"./as": "./as/mod.ts",
Expand Down
4 changes: 2 additions & 2 deletions is/literal_one_of.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<T extends readonly Primitive[]>(
export function isLiteralOneOf<const T extends readonly Primitive[]>(
literals: T,
): Predicate<T[number]> {
const s = new Set(literals);
Expand Down
12 changes: 12 additions & 0 deletions is/literal_one_of_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,16 @@ Deno.test("isLiteralOneOf<T>", async (t) => {
assertType<IsExact<typeof a, "hello" | "world">>(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<IsExact<typeof b, "foo" | "bar">>(true);
}
});
});