8000 Weak typings for Array.prototype.map · Issue #17015 · microsoft/TypeScript · GitHub
[go: up one dir, main page]

Skip to content
  • Weak typings for Array.prototype.map #17015
    @kujon

    Description

    @kujon

    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.

    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

        0