Typescript: array.map lose literal types

Created on 10 Sep 2018  路  6Comments  路  Source: microsoft/TypeScript


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"'.

Duplicate

All 6 comments

Root cause is #241

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

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

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

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!

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

Was this page helpful?
0 / 5 - 0 ratings

Related issues

quantuminformation picture quantuminformation  路  273Comments

Gaelan picture Gaelan  路  231Comments

kimamula picture kimamula  路  147Comments

fdecampredon picture fdecampredon  路  358Comments

yortus picture yortus  路  157Comments