Skip to content

T[] still inferred as (T | undefined)[] even after filtering out undefined entries explicitlyΒ #45097

Closed
@y-nk

Description

@y-nk

Bug Report

πŸ”Ž Search Terms

filter Boolean undefined

πŸ•— Version & Regression Information

  • Latest version

⏯ Playground Link

Playground link with relevant code

πŸ’» Code

type Model = { id: string }

const models: Model[] = [{ id: '0' }, { id: '1' }, { id: '2' }]

const ids = ['1', '3']

const values = ids
    .map(id => models.find(model => model.id === id))
    .filter(model => model !== undefined) // values type should be Model[]

πŸ™ Actual behavior

values is of type (Model | undefined)[] even though undefined values are excluded thanks to the filter function

πŸ™‚ Expected behavior

values should be of type Model[]

Metadata

Metadata

Assignees

No one assigned

    Labels

    Design LimitationConstraints of the existing architecture prevent this from being fixed

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions