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
There is a conditional operator literal string type problem, ts cannot resolve true ? "a" : "b" as a type, which may call some errors.
for example:
typea_or_b="a"|"b";letv1=(true ? "a" : "b");letv2: a_or_b;v2=v1;// ERROR
Expected behavior:
expect no error.
Actual behavior:
but it comes up with an error as follow:
TS2322
I know a solution to refrain this error is changing the line 2 to be let v1: any = (true ? "a" : "b"); or let v1: a_or_b = (true ? "a" : "b"); , but this procedure seem to should be needless.
The text was updated successfully, but these errors were encountered:
Try const v1 = (true ? "a" : "b");. Since you are using let you are allowing v1 to be reassigned and the compiler assumes you want it to accept the wider range of values (string), but with const it can be narrower.
(What actually surprises me here is that it infers the type of const v1 as "a" | "b" rather than "a" which is clearly the only thing it can actually be; I made a separate bug for that)
TypeScript Version: 2.1.5
There is a conditional operator literal string type problem, ts cannot resolve
true ? "a" : "b"
as a type, which may call some errors.for example:
Expected behavior:
expect no error.
Actual behavior:

but it comes up with an error as follow:
TS2322
I know a solution to refrain this error is changing the line 2 to be
let v1: any = (true ? "a" : "b");
orlet v1: a_or_b = (true ? "a" : "b");
, but this procedure seem to should be needless.The text was updated successfully, but these errors were encountered: