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
Error TS2345: Argument of type 'string' is not assignable to parameter of type '"AAA" | "BBB"'.
The text was updated successfully, but these errors were encountered:
k8w
changed the title
Type not judged as string literal when using ternary operator
Variable not recognized as string literal type when using ternary operator
Nov 3, 2016
First, you are assigning to a let variable, which means the compiler will assume that you may want to change the value in the future, therefore it does not assign a string literal type to the variable.
Also, in 2.0, there was never an inference of literals. The developer would have to do that explicitly. So to fix this:
TypeScript Version: 2.0.3 / nightly (2.1.0-dev.201xxxxx)
2.0.3
Code
Expected behavior:
Compiled successfully
Actual behavior:
Got error:
The text was updated successfully, but these errors were encountered: