I have a simple arrow function:
const db = (url, type, body?) => ({url, type, body})
and I don't want to return body property if it's an empty db argument.
You can do:
const db = (url, type, body) => (body ? {url, type, body} : {url, type})
You can check this way
const db = (url, type, body) => (Object.keys(body).length > 0 ? { url, type, body } : { url, type })
undefined? That's exactly whatbodyshould become when you want to "omit" it - your code already works!