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

Hashmap (unexpectedly) doesn't include undefined as a possible return value when using strictNullChecks #11186

Closed
DanTup opened this issue Sep 27, 2016 · 4 comments
Labels
Duplicate An existing issue was already created

Comments

@DanTup
Copy link

DanTup commented Sep 27, 2016

Apologies if this has been covered before an/or is not a bug but I can't seem to find it in the issue list or any discussion of it online.

TypeScript Version: 2.0.3

Given this code:

let danny: { [name: string]: string; } = {};
let whatIsMyType = danny["test2"];

the type of whatIsMyType is string (I would expect string | undefined). This means I can write a method that pulls from the map and claims to return a string without any warning:

getPackagePath(name: string): string {
    return this.map[name];
}

Shouldn't | undefined be added implicitly to the type returned from a map like this?

@normalser
Copy link

#7140 (comment)

@blakeembrey
Copy link
Contributor

blakeembrey commented Sep 27, 2016

Same issue as #9235.

@mhegazy mhegazy added the Duplicate An existing issue was already created label Sep 27, 2016
@mhegazy
Copy link
Contributor

mhegazy commented Sep 27, 2016

closing in favor of #9235.

@ewinslow
Copy link

ewinslow commented Oct 5, 2016

@mhegazy I think you forgot to close

@microsoft microsoft locked and limited conversation to collaborators Jun 19, 2018
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

6 participants