Skip to content

Array filter on array does not correct types returned from map #35988

@alzalabany

Description

@alzalabany

Search Terms:
Type Array filter

Code

type T = { id:number };
const obj = [{id:1},{id:2},{id:3}]
const ids = [1,2,5];
const error:T[] = ids.map(id=>obj[id] ? obj[id] : false).filter(Boolean);

Expected behavior:
const error should be T[] only;

Actual behavior:
// error type is T | false

Related Issues:
7657

Metadata

Metadata

Assignees

No one assigned

    Labels

    DuplicateAn existing issue was already created

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions