Skip to content

Narrow types when using Array.filter #2835

Closed
@NoelAbrahams

Description

@NoelAbrahams

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*/);

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