Skip to content

array.map lose literal types #26999

Closed
Closed

Description

@cevek

TypeScript Version: 3.1.0-dev.20180906

Search Terms:

Code

interface Item {
    x: number;
    y: 'a' | 'b'
}
var list:Item[] = [].map(it => ({x: 1, y: 'a'}))

Expected behavior:
No error

Actual behavior:
Type 'string' is not assignable to type '"a" | "b"'.

Activity

  1. RyanCavanaugh commented on Sep 10, 2018

    @RyanCavanaugh
    Member

    Root cause is #241

  2. typescript-bot commented on Dec 14, 2018

    @typescript-bot
    Contributor

    This issue has been marked as a 'Duplicate' and has seen no recent activity. It has been automatically closed for house-keeping purposes.

  3. thw0rted commented on Sep 9, 2020

    @thw0rted

    This will be fixed by #40311, see the comment I just left on #33158.

  4. DanielRosenwasser commented on Sep 9, 2020

    @DanielRosenwasser
    Member

    It won't be fixed by #40311 unfortunately (see the "Future Work" section in the PR writeup)

  5. thw0rted commented on Sep 10, 2020

    @thw0rted

    Well crud. This is all my fault, I had a bunch of related tabs open and posted this comment in a few of them where I thought the issue being reported was the same -- this wasn't one of them. Sorry!

  6. DanielRosenwasser commented on Sep 10, 2020

    @DanielRosenwasser
    Member

    Don't sweat it, I had the same enthusiasm at first. 😅

  7. locked as resolved and limited conversation to collaborators on Oct 21, 2025
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