Skip to content

Narrow types when using Array.filter #2835

Closed

Description

Hi,

Will this be possible?

var foo: (number|string)[] = [1, 'bar'];

foo.filter(item => typeof item ==='string').map(item => item/*string type*/);
foo.filter(item => typeof item !=='string').map(item => item/*number type*/);

Activity

  1. RyanCavanaugh commented on Apr 20, 2015

    @RyanCavanaugh
    Member

    Not happening unless someone can figure out a reasonable way to write a signature for filter in a way that is generalizable.

  2. locked and limited conversation to collaborators on Jun 18, 2018
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

    SuggestionAn idea for TypeScriptToo ComplexAn issue which adding support for may be too complex for the value it adds

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions