Skip to content

Latest commit

 

History

History

is-readonly-array

@sounisi5011/ts-type-util-is-readonly-array

Go to the latest release page on npm

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 {
        // ...
    }
}