Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
jpanda109 opened this issue Dec 25, 2016 · 1 comment
Closed
Labels
Duplicate An existing issue was already created

Comments

@jpanda109
Copy link

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

@aluanhaddad
Copy link
Contributor

Duplicate of #9235

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Duplicate An existing issue was already created
Projects
None yet
Development

No branches or pull requests

3 participants