From aec15fcb6ef0a6b987725c5a5a88455a05a7f97d Mon Sep 17 00:00:00 2001 From: Alisue Date: Sun, 26 Nov 2023 21:24:37 +0900 Subject: [PATCH] :+1: Add `isUnknown` predicate function --- is.ts | 8 ++++++++ is_test.ts | 21 +++++++++++++++++++++ 2 files changed, 29 insertions(+) diff --git a/is.ts b/is.ts index 5f19c28..4430ee4 100644 --- a/is.ts +++ b/is.ts @@ -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`. */ @@ -508,6 +515,7 @@ export function isOptionalOf( export default { Any: isAny, + Unknown: isUnknown, String: isString, Number: isNumber, BigInt: isBigInt, diff --git a/is_test.ts b/is_test.ts index dadfbcf..e119a3b 100644 --- a/is_test.ts +++ b/is_test.ts @@ -36,6 +36,7 @@ import is, { isTupleOf, isUndefined, isUniformTupleOf, + isUnknown, Predicate, PredicateType, } from "./is.ts"; @@ -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", + ], + }); +}); + Deno.test("isString", async (t) => { await testWithExamples(t, isString, { validExamples: ["string"] }); });