Skip to content

Unexpected implicit any for return value of Array<T>.indexOf #29290

Open
@connorjclark

Description

@connorjclark

TypeScript Version: 3.3.0-dev.20190105

Search Terms: evolving array type, indexOf

Code

const arr = [];

arr.push(1);

while (true) {
    const index = arr.indexOf(1);
    arr[index] = 1;
}

Expected behavior:

No errors.

Actual behavior:

'index' implicitly has type 'any' because it does not have a type annotation and is referenced directly or indirectly in its own initializer.

Playground Link: (turn on noImplicitAny)

Related Issues: #19955

In the wild: GoogleChrome/lighthouse#6874 (comment). Note @brendankenny's educated guess on what is going on.

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugA bug in TypeScriptDomain: Control FlowThe issue relates to control flow analysis

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions