Skip to content

noUncheckedIndexedAccess behaves differently b/w type-level and value-level access #62534

@juhort

Description

@juhort

Acknowledgement

  • I acknowledge that issues using this template may be closed without further explanation at the maintainer's discretion.

Comment

The output of accessing a property from an index signature is different between type-level access and value-level access.

// @noUncheckedIndexedAccess: true

type IndexSig = {[x: string]: number}
type AccessFromIndexSig = IndexSig[string]
//   ^? type AccessFromIndexSig = number

declare const indexSig: IndexSig;
declare const accessor: string;
const accessFromIndexSig = indexSig[accessor];
//    ^? const accessFromIndexSig: number | undefined

Playground

I expect it to have the extra undefined for the type-level access as well. Is this intentional?

Metadata

Metadata

Assignees

No one assigned

    Labels

    Working as IntendedThe behavior described is the intended behavior; this is not a bug

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions