Skip to content

the provided API functions do not appear to be type-safe #1

@highmtworks

Description

@highmtworks

The following example causes TypeError:

// const arr: string[]
const arr = ['a'];

if (hasLength(arr, 1)) {
  // README claims: arr: readonly [string]
  // but actually: arr: string[] & readonly [string]
  arr.shift();
  const str: string = arr[0];

  // TypeError: Cannot read properties of undefined (reading 'length')
  console.log(str.length);
}

with tsconfig.json:

{
  "compilerOptions": {
    // ...
    "strict": true,
    "exactOptionalPropertyTypes": true,
    "noUncheckedIndexedAccess": true,
    // ...
  }
}
>npx tsc --version
Version 4.9.5

>node --version
v18.14.2

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions