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

Weak typings for Array.prototype.map #17015

Closed
kujon opened this issue Jul 7, 2017 · 2 comments
Closed

Weak typings for Array.prototype.map #17015

kujon opened this issue Jul 7, 2017 · 2 comments
Labels
Duplicate An existing issue was already created

Comments

@kujon
Copy link
Contributor

kujon commented Jul 7, 2017

TypeScript Version: 2.4.0

Code

The following blows up nicely as expected:

type A = {
    foo: string;
};

/** 'baz' does not exist in type 'A' */
const test1: A[] = [{ foo: 'foo', baz: 42 }];

Put it through the map method though, and any extra fields will be silently accepted:

/** no error */
const test2: A[] = ['foo'].map(val => ({ foo: val, baz: 42 }));

Expected behavior:
Both examples blow up w/ 'baz' does not exist in type 'A'

Actual behavior:
Only the compilation of the first example fails.

@ghost
Copy link

ghost commented Jul 7, 2017

Duplicate of #11152 / #3423.
Currently we can't determine a contextual type for the returned expression, so extra properties aren't checked.

@ghost ghost added the Duplicate An existing issue was already created label Jul 7, 2017
@mhegazy
Copy link
Contributor

mhegazy commented Aug 17, 2017

Automatically closing this issue for housekeeping purposes. The issue labels indicate that it is unactionable at the moment or has already been addressed.

@mhegazy mhegazy closed this as completed Aug 17, 2017
@microsoft microsoft locked and limited conversation to collaborators Jun 14, 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

2 participants