@sounisi5011/ts-utils-is-property-accessible
v1.0.3
Published
Check if a value is property accessible
Downloads
62
Maintainers
Readme
@sounisi5011/ts-utils-is-property-accessible
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.
}