镜像站点 · 本页由第三方 GitHub 只读镜像提供,非 GitHub 官方站点,不接受任何登录或凭据输入。前往 github.com
Skip to content

Suggestion: Let indexable types have return type (<type> | undefined) #13161

Description

@jpanda109

TypeScript Version: 2.1.4

Allowing indexing of indexable interfaces act similar to ES6 Map.get seems like it would help the type safety of the language.

Example:

interface Foo {
    [name: string]: number
}
let foo: Foo = {};
let baz = foo["bar"];
// baz is of type number and compiles fine, even though is actually undefined
// possibly make baz of type (number | undefined) instead

Expected Behavior:
baz is of type (number | undefined)

Actual Behavior:
baz is of type number, despite actually being type undefined

No activity

Activity on this issue will appear here.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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