Skip to contentSlop Block

no-conditional-empty-object-spread

Warning

Do not spread a conditional object with an empty branch, such as ...(condition ? { value } : {}).

const options = {	...(timeout !== undefined ? { timeout } : {}),Do not spread a conditional object with an empty branch};
const options = { ...(enabled ? {} : { disabled: true }) };Do not spread a conditional object with an empty branch
// ast-grep-ignore: no-conditional-empty-object-spread-typescript

How to fix

Omitting a key and setting it to undefined behave differently, so there is no automatic fix.

Build the object step by step, or pass the value and let the callee handle undefined.