Javascript typically uses the following pattern:
It does not follow. Having multiple objects of various shapes can result in a performance penalty. Entries must always contain the same keys. Therefore just use
const obj = { requiredKey1: …, requiredKey2: …, optionalKey1: someCondition ? … : undefined, };
Bergi source share