From e306fa60cab427c66585c326893c841b64acc629 Mon Sep 17 00:00:00 2001 From: D-Sketon <2055272094@qq.com> Date: Sun, 15 Mar 2026 20:29:03 +0800 Subject: [PATCH] fix(isEmpty): handle functions with own enumerable properties --- src/compat/predicate/isEmpty.spec.ts | 7 +++++++ src/compat/predicate/isEmpty.ts | 2 +- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/src/compat/predicate/isEmpty.spec.ts b/src/compat/predicate/isEmpty.spec.ts index bccc3448d..51b8086e9 100644 --- a/src/compat/predicate/isEmpty.spec.ts +++ b/src/compat/predicate/isEmpty.spec.ts @@ -33,6 +33,13 @@ describe('isEmpty', () => { expect(isEmpty('a')).toBe(false); }); + it('should return `false` for functions with own enumerable properties', () => { + function transaction() {} + transaction.commit = () => {}; + + expect(isEmpty(transaction)).toBe(false); + }); + it('should work with an object that has a `length` property', () => { expect(isEmpty({ length: 0 })).toBe(false); }); diff --git a/src/compat/predicate/isEmpty.ts b/src/compat/predicate/isEmpty.ts index 628c8c3c3..47c65a6be 100644 --- a/src/compat/predicate/isEmpty.ts +++ b/src/compat/predicate/isEmpty.ts @@ -63,7 +63,7 @@ export function isEmpty(value?: unknown): boolean { return value.length === 0; } - if (typeof value === 'object') { + if (typeof value === 'object' || typeof value === 'function') { if (value instanceof Map || value instanceof Set) { return value.size === 0; }