Skip to content

Type of element selected from (potentially) empty arrayΒ #47060

Description

@jaksenko

Bug Report

πŸ”Ž Search Terms

array index element undefined

πŸ•— Version & Regression Information

  • This is the behavior in every version I tried, and I reviewed the FAQ for entries about type of element selected from (potentially) empty array

⏯ Playground Link

Playground link with relevant code

πŸ’» Code

const ary: string[] = [];
const firstElement = ary[0];
// `firstElement`'s type is `string` while it should be `string | undefined`
// or even better `undefined` since that can be deduced from the line above.

πŸ™ Actual behavior

firstElement is of type string.

πŸ™‚ Expected behavior

firstElement should be of type string | undefined or undefined if that can be deduced.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions