You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
type dis = 'a' | 'b' | 'c';
type Cmap = Map<dis, number>;
var a: Cmap = new Map([['a', 2], ['b', 3]]);
type dis = 'a' | 'b' | 'c';
let a = 'a';
let b:dis = a;
Expected behavior:
inferred type of a is Map<dis, number>
inferred type of b is dis
Actual behavior:
inferred type of a is Map<string, number>
inferred type of b is string
Hello !
There is no map notation, so we have to use the Map constructor. However, it is not correctly typed, and requires type annotation () at every construction.
EDIT : The problem is not with Map. Cf, the other example.
It looks like the string union type is not propagated.
I found it to be expected when a is explicitely typed as 'string'. But when no annotation is given, I did not find the expected semantic.
As such, I do not know if it is a bug, or by design, but I did not find anything referring to that particular issue.
Have a good day !
The text was updated successfully, but these errors were encountered:
Galfour
changed the title
Type inference for Maps constructor
Type inference for string disjunction
Aug 5, 2016
Galfour
changed the title
Type inference for string disjunction
Type inference for string literal union
Aug 5, 2016
TypeScript Version: 1.8.0 / nightly (2.0.0-dev.201xxxxx)
Expected behavior:
inferred type of a is Map<dis, number>
inferred type of b is dis
Actual behavior:
inferred type of a is Map<string, number>
inferred type of b is string
Hello !
There is no map notation, so we have to use the Map constructor. However, it is not correctly typed, and requires type annotation () at every construction.
EDIT : The problem is not with Map. Cf, the other example.
It looks like the string union type is not propagated.
I found it to be expected when a is explicitely typed as 'string'. But when no annotation is given, I did not find the expected semantic.
As such, I do not know if it is a bug, or by design, but I did not find anything referring to that particular issue.
Have a good day !
The text was updated successfully, but these errors were encountered: