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

オープン
#829 コメント 0 件 リアクション 0 件 担当者 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時間
マージ済み PR(30日)
1

環境構築

このプロジェクトには開発コンテナ、Dockerfile、コントリビューションガイドがありません。まず README を読み、一般的な手順ははじめてのコントリビューションガイドを参照してください。

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

react-component/util のほかの issue

react-component/util の issue をすべて見る

似ている issue

TypeScript の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。