Check if a value is property accessible.
npm install @sounisi5011/ts-utils-is-property-accessible
yarn add @sounisi5011/ts-utils-is-property-accessible
pnpm add @sounisi5011/ts-utils-is-property-accessible
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.
}
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.
}
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.
}