@sounisi5011/ts-type-util-is-readonly-array
v1.0.2
Published
Fix the type definition of `Array.isArray()` method to accept readonly arrays
Downloads
233
Maintainers
Readme
@sounisi5011/ts-type-util-is-readonly-array
Fix the type definition of Array.isArray()
method to accept readonly arrays.
Installation
npm install @sounisi5011/ts-type-util-is-readonly-array
yarn add @sounisi5011/ts-type-util-is-readonly-array
pnpm add @sounisi5011/ts-type-util-is-readonly-array
Usage
import { isReadonlyArray } from '@sounisi5011/ts-type-util-is-readonly-array';
const isArray = Array.isArray as isReadonlyArray;
if (isArray(value)) {
// ...
}
function fn(param: string | readonly string[]) {
if (isArray(param)) {
// ...
} else {
// ...
}
}
or
import { isReadonlyArray } from '@sounisi5011/ts-type-util-is-readonly-array';
if ((Array.isArray as isReadonlyArray)(value)) {
// ...
}
function fn(param: string | readonly string[]) {
if ((Array.isArray as isReadonlyArray)(param)) {
// ...
} else {
// ...
}
}