Skip to content

Array.prototype.filter definition forces a boolean #5850

Closed
@denis-sokolov

Description

@denis-sokolov

It is natural to use Array.prototype.filter to filter items with missing information:

type Foo = { prop: string }

const a: Foo[] = [
    { prop: 'bar' },
    { prop: null },
    { prop: 'baz' }
] 

a.filter(x => x.prop)

Unfortunately, this does not compile, as filter definition requires the result of the filter function to be strictly boolean. Would it make sense to make the filter definition less strict?

Metadata

Metadata

Assignees

No one assigned

    Labels

    Domain: lib.d.tsThe issue relates to the different libraries shipped with TypeScriptFixedA PR has been merged for this issueGood First IssueWell scoped, documented and has the green lightHelp WantedYou can do thisSuggestionAn idea for TypeScript

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions