Skip to content

Indexed array access type is not possibly undefined with noUncheckedIndexAccess enabledย #51419

@BrianESimon

Description

@BrianESimon

Bug Report

๐Ÿ”Ž Search Terms

noUncheckedIndexAccess, array

๐Ÿ•— Version & Regression Information

  • This is the behavior in every version I tried, and I reviewed the FAQ for entries about noUncheckedIndexAccess

โฏ Playground Link

Playground link with relevant code

๐Ÿ’ป Code

With noUncheckedIndexAccess enabled:

const arr: string[] = [];

type IncorrectArrayType = typeof arr[0]; // string

// there's a workaround, but it involves runtime overhead
const correct = arr[0];
type CorrectArrayType = typeof correct; // string | undefined

๐Ÿ™ Actual behavior

Indexing an array type doesn't include undefined with noUncheckedIndexAccess enabled

๐Ÿ™‚ Expected behavior

IncorrectArrayType should be string | undefined

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions