Skip to content

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

Description

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

Activity

  1. MartinJohns commented on Jan 4, 2020

    @MartinJohns
    Contributor

    Duplicate of #32834, #31164, #24063, #16655. Was implemented by #29955, and broken by #31515.

    Search terms used: filter boolean

  2. typescript-bot commented on Jan 9, 2020

    @typescript-bot
    Contributor

    This issue has been marked as a 'Duplicate' and has seen no recent activity. It has been automatically closed for house-keeping purposes.

  3. OmgImAlexis commented on May 12, 2020

    @OmgImAlexis

    Martin Johns (@MartinJohns) since this was broken by #31515 can we get a new issue open to track this? Otherwise you're just going to keep closing issues as duplicates.

  4. MartinJohns commented on May 12, 2020

    @MartinJohns
    Contributor

    Alexis Tyler (@OmgImAlexis) I'm not a member of the TypeScript team, so I have no say in this. But.. why get a new issue? There are existing issues about this, see my comment from before: #35988 (comment)

  5. OmgImAlexis commented on May 12, 2020

    @OmgImAlexis

    The first two issues you linked were closed, I had assumed the others were too.

  6. locked as resolved and limited conversation to collaborators on Oct 21, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    DuplicateAn existing issue was already created

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions