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
8 changes: 8 additions & 0 deletions is.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,13 @@ export function isAny(_x: unknown): _x is any {
return true;
}

/**
* Always return `true` regardless of the type of `x`.
*/
export function isUnknown(_x: unknown): _x is unknown {
return true;
}

/**
* Return `true` if the type of `x` is `string`.
*/
Expand Down Expand Up @@ -508,6 +515,7 @@ export function isOptionalOf<T>(

export default {
Any: isAny,
Unknown: isUnknown,
String: isString,
Number: isNumber,
BigInt: isBigInt,
Expand Down
21 changes: 21 additions & 0 deletions is_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ import is, {
isTupleOf,
isUndefined,
isUniformTupleOf,
isUnknown,
Predicate,
PredicateType,
} from "./is.ts";
Expand Down Expand Up @@ -135,6 +136,26 @@ Deno.test("isAny", async (t) => {
});
});

Deno.test("isUnknown", async (t) => {
await testWithExamples(t, isUnknown, {
validExamples: [
"string",
"number",
"bigint",
"boolean",
"array",
"record",
"syncFunction",
"asyncFunction",
"null",
"undefined",
"symbol",
"date",
"promise",
],
});
});
Comment on lines +139 to +157
Copy link

Choose a reason for hiding this comment

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

The test case for isUnknown is incorrectly expecting true for all known types, which contradicts the intended functionality of the function. The test should be set up to expect false for known types and true for unknown types.


Deno.test("isString", async (t) => {
await testWithExamples(t, isString, { validExamples: ["string"] });
});
Expand Down