isEqual returns true for objects with different keys when a value is undefined, and for {} vs []

Đang mở
#829 0 bình luận 0 reaction 0 người được giao Xem trên GitHub

@bardrop đang làm issue này rồi.

Từ ngày 14/11/2026.

  • #830 của @bardrop — đang mở

Đánh giá

Độ khó
2/5
Thời gian dự kiến
1-3 giờ
Mức phù hợp với người mới
25/100
Loại issue
Lỗi
Độ rõ ràng
Đặc tả rõ ràng
Mức độ hoạt động
Sôi nổi
Công nghệ
react, typescript
Lĩnh vực
frontend

Hướng nghiên cứu

The bug is in the object branch of src/isEqual.ts, which compares key counts and then recurses only over the keys of a. Read that branch first, and check how it handles array versus object inputs and keys missing from b. Pull request #830 is already open against this issue, so review it before starting new work. Done means the five calls in the repro script return false, and the existing isEqual tests still pass.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

isEqual returns true for objects with different keys when one has an undefined value, and when comparing an object with an array.

// npm i @rc-component/[email protected]
const isEqual = require("@rc-component/util/lib/isEqual").default;

console.log(isEqual({ a: undefined }, { b: 1 }));             // true
console.log(isEqual({ a: 1, b: undefined }, { a: 1, c: 2 })); // true
console.log(isEqual({}, []));                                 // true
console.log(isEqual({ 0: 1 }, [1]));                          // true
console.log(isEqual([1], { 0: 1 }));                          // false

Command: node repro.cjs

Actual output:

true
true
true
true
false

Expected output: false for all five calls.

In src/isEqual.ts, the object branch compares Object.keys(a).length !== Object.keys(b).length and then checks deepEqual(a[key], b[key]) only for the keys of a, without checking Array.isArray(b) or Object.prototype.hasOwnProperty.call(b, key).

Version: @rc-component/[email protected] and master (149b6c2585), tested on Node v26.13.0. (Separate from #816.)

Credit: https://ucsbplse.github.io/

Ngôn ngữ chính
TypeScript
Star
671
Fork
214
Merge trung bình
2 ngày 1 giờ
Pull request đã merge (30 ngày)
1

Chuẩn bị môi trường

Dự án này không cung cấp dev container, Dockerfile hay hướng dẫn đóng góp, nên bạn cần tự thiết lập môi trường: hãy bắt đầu từ README và xem hướng dẫn đóng góp lần đầu của chúng tôi để biết các bước chung.

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của react-component/util

Tất cả issue của react-component/util

Issue tương tự

Thêm issue về TypeScript

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.