Skip to content
Junior–Senior164 views

Ensuring standard safety of the property addition function

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 }
Frontend tasks in the code trainer