Skip to content

Latest commit

 

History

History

is-property-accessible

@sounisi5011/ts-utils-is-property-accessible

Go to the latest release page on npm Tested with Jest Commitizen friendly Minified Bundle Size Details Install Size Details Dependencies Status Build Status Maintainability Status

Check if a value is property accessible.

Installation

npm install @sounisi5011/ts-utils-is-property-accessible
yarn add @sounisi5011/ts-utils-is-property-accessible
pnpm add @sounisi5011/ts-utils-is-property-accessible

Usage

TypeScript

import { isPropertyAccessible } from '@sounisi5011/ts-utils-is-property-accessible';

if (isPropertyAccessible(value)) {
    // `value.anyProperty` is available!
    // Because the value is neither null nor undefined.
    // In addition, an index signature type will be added so that any property can be read.
} else {
    // If you try to read or write any property, a TypeError will probably be thrown.
    // Because the value is null or undefined.
}

JavaScript (ES Modules)

import { isPropertyAccessible } from '@sounisi5011/ts-utils-is-property-accessible';

if (isPropertyAccessible(value)) {
    // `value.anyProperty` is available!
    // Because the value is neither null nor undefined.
} else {
    // If you try to read or write any property, a TypeError will probably be thrown.
    // Because the value is null or undefined.
}

JavaScript (CommonJS)

const { isPropertyAccessible } = require('@sounisi5011/ts-utils-is-property-accessible');

if (isPropertyAccessible(value)) {
    // `value.anyProperty` is available!
    // Because the value is neither null nor undefined.
} else {
    // If you try to read or write any property, a TypeError will probably be thrown.
    // Because the value is null or undefined.
}