Skip to content

Commit 6cdf1e3

Browse files
authored
Merge pull request #44 from lambdalisue/add-is-unknown
👍 Add `isUnknown` predicate function
2 parents 8f8d181 + aec15fc commit 6cdf1e3

File tree

2 files changed

+29
-0
lines changed

2 files changed

+29
-0
lines changed

is.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,13 @@ export function isAny(_x: unknown): _x is any {
1818
return true;
1919
}
2020

21+
/**
22+
* Always return `true` regardless of the type of `x`.
23+
*/
24+
export function isUnknown(_x: unknown): _x is unknown {
25+
return true;
26+
}
27+
2128
/**
2229
* Return `true` if the type of `x` is `string`.
2330
*/
@@ -508,6 +515,7 @@ export function isOptionalOf<T>(
508515

509516
export default {
510517
Any: isAny,
518+
Unknown: isUnknown,
511519
String: isString,
512520
Number: isNumber,
513521
BigInt: isBigInt,

is_test.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ import is, {
3636
isTupleOf,
3737
isUndefined,
3838
isUniformTupleOf,
39+
isUnknown,
3940
Predicate,
4041
PredicateType,
4142
} from "./is.ts";
@@ -135,6 +136,26 @@ Deno.test("isAny", async (t) => {
135136
});
136137
});
137138

139+
Deno.test("isUnknown", async (t) => {
140+
await testWithExamples(t, isUnknown, {
141+
validExamples: [
142+
"string",
143+
"number",
144+
"bigint",
145+
"boolean",
146+
"array",
147+
"record",
148+
"syncFunction",
149+
"asyncFunction",
150+
"null",
151+
"undefined",
152+
"symbol",
153+
"date",
154+
"promise",
155+
],
156+
});
157+
});
158+
138159
Deno.test("isString", async (t) => {
139160
await testWithExamples(t, isString, { validExamples: ["string"] });
140161
});

0 commit comments

Comments
 (0)