Skip to content

Array.some should reflect that the array is not empty #60103

Description

⚙ Compilation target

es5

⚙ Library

es5

Missing / Incorrect Definition

some in lib.es5.d.ts could be defined as follows (return type from boolean to this is [T, ...T[]]):

interface Array<T> {
    some(predicate: (value: T, index: number, array: T[]) => unknown, thisArg?: any): this is [T, ...T[]];
}

Sample Code

playground

function requiresOneItem<T>(array: [T, ...T[]]) {}
function isFoo<T>(item: T) { return true }

const array = [1, 2]

if (array.some(isFoo)) {
  requiresOneItem(array) // Argument of type 'number[]' is not assignable to parameter of type '[number, ...number[]]'.
}


interface Array<T> {
    // Uncomment to test:
    // some(predicate: (value: T, index: number, array: T[]) => unknown, thisArg?: any): this is [T, ...T[]];
}

Documentation Link

N.A. Calling .some() on an array can only ever return true if the array is not empty.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Working as IntendedThe behavior described is the intended behavior; this is not a bug

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions