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

Aperta
#829 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

@bardrop ci sta già lavorando.

Dal 14/11/2026.

  • #830 di @bardrop — aperta

Valutazione

Difficoltà
2/5
Tempo stimato
1-3 ore
Idoneità per principianti
25/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
react, typescript
Ambito
frontend

Direzione di ricerca

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.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

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/

Lingua principale
TypeScript
Stelle
671
Fork
214
Merge medio
2g 1h
PR unite (30g)
1

Preparare l'ambiente

Questo progetto non fornisce container di sviluppo, Dockerfile né guida per i contributori, quindi l'ambiente è a tuo carico: parti dal suo README e consulta la nostra guida al primo contributo per i passaggi generali.

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di react-component/util

Tutte le issue di react-component/util

Issue simili

Altre issue su TypeScript

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.