Objects.isWritable()

Syntax

function isWritable(object: unknown, property: string | number | symbol): boolean

Gets a value indicating whether a property can be written to.

Parameters
object

The object to retrieve the constructor of.

Example

import { Objects } from 'potence';

const object = {
    writableValue: 5,
    get readonlyValue() { return 5; }
}

Objects.isWritable(object, 'writableValue');  // -> true
Objects.isWritable(object, 'readonlyValue');  // -> false

Remarks

A property can be written to if its writable field is true or if it has a setter function associated with it.

This function uses Objects.getPropertyDescriptor() under the hood, so even inherited properties will be processed correctly.

This function is also a type guard, meaning that it will assert that the property exists on the target if it returns true.