TypeScript Version: 3.4.0-dev.201xxxxx
Search Terms: union, index type
Code
classTest<PropsextendsObject>{constructor(publico: Props){}get<KextendskeyofProps>(k: K) : Props[K]{returnthis.o[k];}}interfaceA{t: "A";};interfaceB{t: "B";};typeu=Test<A>|Test<B>;consttmp=newTest<B>({t: 'B'})asu;switch(tmp.get('t')){case'A': break;case'B': break;}Expected behavior:
Code compiles with tmp.get('t') having type "A" | "B".
This works for:
Actual behavior:
Compilation fails with error:
Type '"B"' is not comparable to type '"A"'.
Type of tmp.get('t') is only "A".
Problem is not contained to string literals, but also other types. Enountered this bug using immutable-js Record.get().
Playground Link:playground
Related Issues: None found
TypeScript Version: 3.4.0-dev.201xxxxx
Search Terms: union, index type
Code
Expected behavior:
Code compiles with
tmp.get('t')having type"A" | "B".This works for:
Actual behavior:
Compilation fails with error:
Type of
tmp.get('t')is only"A".Problem is not contained to string literals, but also other types. Enountered this bug using immutable-js Record.get().
Playground Link:playground
Related Issues: None found