From 30a9b80359e63f9fe3ff470a23a844d1b23a1781 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9E=9C=E5=AD=90?= Date: Wed, 13 May 2026 23:24:48 +0800 Subject: [PATCH] fix: handle null in isJSONSerializable (#571) `typeof null` returns `"object"`, not `null`, so the check `t === null` was dead code. This caused `null` to fall through to the `value.buffer` check, throwing a TypeError. Fix by checking `value === null` explicitly before the typeof checks. Since `null` is valid JSON (`JSON.stringify(null)` === `"null"`), it should return `true`. --- src/utils.ts | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/utils.ts b/src/utils.ts index a773431b..2e79fc7a 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -18,8 +18,11 @@ export function isJSONSerializable(value: any): boolean { if (value === undefined) { return false; } + if (value === null) { + return true; + } const t = typeof value; - if (t === "string" || t === "number" || t === "boolean" || t === null) { + if (t === "string" || t === "number" || t === "boolean") { return true; } if (t !== "object") {