Sobes.tech
Junior — Senior

Ensuring standard safety of the property addition function

livecode

Task condition

It is necessary to add type annotations to the addProperty function to ensure safe extension of objects with new fields.

function addProperty(obj, key, value) {
    return { ...obj, [key]: value };
}

const original = { name: "Alice" };

const updated = addProperty(original, "age", 25);

console.log(updated);
// Output: { name: 'Alice', age: 25 }