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

未關閉
#829 0 則留言 0 個 reaction 已指派 0 人 在 GitHub 檢視

@bardrop 已經在處理了。

開始於 2026年11月14日。

  • #830 來自 @bardrop —— 未關閉

評估

難度
2/5
預估耗時
1-3 小時
新手友好度
25/100
Issue 類型
缺陷
描述清晰度
描述清楚
活躍度
活躍
技術堆疊
react, typescript
領域
frontend

研究方向

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.

由索引模型根據 Issue 內容生成。

描述

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/

主要語言
TypeScript
星號
671
分支
214
平均合併
2 天 1 小時
30 天內合併 PR
1

環境準備

這個專案沒有提供開發容器、Dockerfile 或貢獻指南,環境需要你自己搭建:先看它的 README,通用步驟見我們的新手貢獻指南。

從這裡開始

  1. 先讀完整個 Issue,再讀專案的貢獻指南。
  2. 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
  3. Fork 儲存庫,在一個分支上完成修改。
  4. 送出 Pull Request,並在描述裡引用這個 Issue 編號。

react-component/util 的其他 Issue

查看 react-component/util 的全部 Issue

相似的 Issue

更多 TypeScript Issue

把新 issue 寄到你的電子郵件信箱

精選適合新手參與的 GitHub issue 摘要。