Skip to content

seal

The seal function recursively seals an object, preventing the addition or removal of properties.

Syntax

typescript
seal(obj): object

Parameters

NameTypeDescription
objobjectObject to be sealed.

Return

TypeDescription
objectReturns the sealed object.

Examples

typescript
const obj = { a: 1, b: { c: 2 } };
seal(obj);
// obj and obj.b cannot have properties added or removed

Notes

  • Internally uses Object.seal recursively.
  • Existing properties can still be modified, but not added or removed.
  • Useful for protecting data structures from structural changes.

References

Released under the MIT License.