@sounisi5011/ts-type-util-is-readonly-array
TypeScript icon, indicating that this package has built-in type declarations

1.0.2 • Public • Published

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

Package Sidebar

Install

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

Weekly Downloads

42

Version

1.0.2

License

MIT

Unpacked Size

4.77 kB

Total Files

5

Last publish

Collaborators

  • sounisi5011