Skip to content

[Bug] Type guarding fails. #21623

@zheeeng

Description

@zheeeng

TypeScript Version: 2.6.2

Code

declare const o: {
    records?: string[]
}

const newRecords = o.records &&
    o.records.map((record, i) => record + (o.records.length === i) ? '' : ',')

Expected behavior:

o.records is safe to using length property.

Actual behavior:

warning:

Object is possibly 'undefined'.
(property) records: string[] | undefined

Playground Link:
playground

Note: enable strict mode is required for reproducing.

Related Issues:

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