Skip to content

Commit 9a9a081

Browse files
committed
👍 Add isAny predicate function
1 parent 155df09 commit 9a9a081

File tree

2 files changed

+29
-0
lines changed

2 files changed

+29
-0
lines changed

is.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,14 @@ export type Predicate<T> = (x: unknown) => x is T;
88
*/
99
export type PredicateType<P> = P extends Predicate<infer T> ? T : never;
1010

11+
/**
12+
* Always return `true` regardless of the type of `x`.
13+
*/
14+
// deno-lint-ignore no-explicit-any
15+
export function isAny(_x: unknown): _x is any {
16+
return true;
17+
}
18+
1119
/**
1220
* Return `true` if the type of `x` is `string`.
1321
*/
@@ -404,6 +412,7 @@ export function isOptionalOf<T>(
404412
}
405413

406414
export default {
415+
Any: isAny,
407416
String: isString,
408417
Number: isNumber,
409418
BigInt: isBigInt,

is_test.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import type {
88
} from "https://deno.land/[email protected]/testing/types.ts";
99
import is, {
1010
isAllOf,
11+
isAny,
1112
isArray,
1213
isArrayOf,
1314
isBigInt,
@@ -108,6 +109,25 @@ Deno.test("PredicateType", () => {
108109
>;
109110
});
110111

112+
Deno.test("isAny", async (t) => {
113+
await testWithExamples(t, isAny, {
114+
validExamples: [
115+
"string",
116+
"number",
117+
"bigint",
118+
"boolean",
119+
"array",
120+
"record",
121+
"function",
122+
"null",
123+
"undefined",
124+
"symbol",
125+
"date",
126+
"promise",
127+
],
128+
});
129+
});
130+
111131
Deno.test("isString", async (t) => {
112132
await testWithExamples(t, isString, { validExamples: ["string"] });
113133
});

0 commit comments

Comments
 (0)