Skip to content

typeof on object index access types don't include undefined when noUncheckedIndexedAccessΒ #42471

Closed
@DetachHead

Description

@DetachHead

Bug Report

πŸ”Ž Search Terms

noUncheckedIndexedAccess

πŸ•— Version & Regression Information

4.2.0-dev.20210124

⏯ Playground Link

https://www.typescriptlang.org/play?noUncheckedIndexedAccess=true&ts=4.2.0-dev.20210124#code/CYUwxgNghgTiAEYD2A7AzgF3gMyUgXPCgK4C2ARiDANoC6AsAFBMYCeADggGJ7wC88NpyTYceagEZa8APQySFKkybJ0WcrEI8k-MUknS5AFQ4IA5Asox4AH3jEUobAEsUIYGfjO0RJFihoaM4A5ihQ5BAIGDpC5pZUZkA

Playground link with relevant code

πŸ’» Code

declare const foo: number[]

type Foo = typeof foo[1] //number

const bar: Foo = foo[1] //Type 'number | undefined' is not assignable to type 'number'

πŸ™ Actual behavior

typeof foo[1] returns number, but the actual type is number|undefined

πŸ™‚ Expected behavior

typeof foo[1] should return number | undefined when noUncheckedIndexedAccess is enabled

Metadata

Metadata

Assignees

No one assigned

    Labels

    QuestionAn issue which isn't directly actionable in code

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions