Skip to content

Commit

Permalink
Merge pull request #124 from jsr-core/nit-fix
Browse files Browse the repository at this point in the history
  • Loading branch information
lambdalisue authored Aug 15, 2024
2 parents d0f6737 + 456e2b9 commit 243dfc5
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 17 deletions.
3 changes: 2 additions & 1 deletion _annotation.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import type { Predicate } from "./type.ts";

export type Fn = (...args: unknown[]) => unknown;
// deno-lint-ignore no-explicit-any
export type Fn = (...args: any[]) => unknown;

export function annotate<F extends Fn, N extends string, V>(
fn: F,
Expand Down
3 changes: 2 additions & 1 deletion _funcutil.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ import { inspect } from "./_inspect.ts";
/**
* Rewrite the function name.
*/
export function rewriteName<F extends (...args: unknown[]) => unknown>(
// deno-lint-ignore no-explicit-any
export function rewriteName<F extends (...args: any[]) => unknown>(
fn: F,
name: string,
...args: unknown[]
Expand Down
2 changes: 1 addition & 1 deletion is/array_of.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export function isArrayOf<T>(
pred: Predicate<T>,
): Predicate<T[]> {
return rewriteName(
(x: unknown): x is T[] => isArray(x) && x.every(pred),
(x: unknown): x is T[] => isArray(x) && x.every((v) => pred(v)),
"isArrayOf",
pred,
);
Expand Down
28 changes: 14 additions & 14 deletions is/object_of.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,22 +43,22 @@ export function isObjectOf<
...Object.keys(predObj),
...Object.getOwnPropertySymbols(predObj),
].map((k) => [k, predObj[k]]);
return annotate(
rewriteName(
(x: unknown): x is ObjectOf<T> => {
if (
x == null ||
typeof x !== "object" && typeof x !== "function" ||
Array.isArray(x)
) return false;
return preds.every(([k, pred]) => pred((x as T)[k]));
},
"isObjectOf",
predObj,
),
"predObj",
const pred = rewriteName(
(x): x is ObjectOf<T> => {
if (!isObject(x)) return false;
return preds.every(([k, pred]) => pred(x[k]));
},
"isObjectOf",
predObj,
);
return annotate(pred, "predObj", predObj);
}

function isObject(x: unknown): x is Record<PropertyKey, unknown> {
if (x == null) return false;
if (typeof x !== "object" && typeof x !== "function") return false;
if (Array.isArray(x)) return false;
return true;
}

type ObjectOf<T extends Record<PropertyKey, Predicate<unknown>>> = FlatType<
Expand Down

0 comments on commit 243dfc5

Please sign in to comment.