Skip to content

Latest commit

 

History

History
24 lines (18 loc) · 545 Bytes

File metadata and controls

24 lines (18 loc) · 545 Bytes
tags
recommended

Disallows useless empty-object fallbacks when spreading into an object literal.

Spreading a nullish value (null or undefined) into an object literal is a no-op, so guarding a spread with || {} or ?? {} accomplishes nothing. The fallback only adds noise and can be removed.

Invalid:

const merged = { ...(foo || {}) };
const merged2 = { ...(foo ?? {}) };

Valid:

const merged = { ...foo };
const merged2 = { ...(foo || { a: 1 }) };
const arr = [...(foo || [])];