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
Expected behavior:
Should work normally and print "Test".
Actual behavior:
A compile-time error is reported (highlighting func):
A signature with an implementation cannot use a string literal type.
In my code I had a function that accepted an argument with a type including only two possible string literal values: say "Value1" and "Value2", e.g function func(val: "Value1" | "Value2"), which worked OK. At some point I decided that "Value2" should not yet be supported so I removed it as an option. This left me with a unary string literal type, e.g. function func(val: "Value1"), but the compiler doesn't seem to like it?
The text was updated successfully, but these errors were encountered:
malibuzios
changed the title
Unary string literal types don't seem to work when applied to function parameters
Unary string literal types don't seem to work when applied to function arguments
Mar 16, 2016
TypeScript Version:
1.8.7
Code
Expected behavior:
Should work normally and print "Test".
Actual behavior:
A compile-time error is reported (highlighting
func
):In my code I had a function that accepted an argument with a type including only two possible string literal values: say
"Value1"
and"Value2"
, e.gfunction func(val: "Value1" | "Value2")
, which worked OK. At some point I decided that "Value2" should not yet be supported so I removed it as an option. This left me with a unary string literal type, e.g.function func(val: "Value1")
, but the compiler doesn't seem to like it?The text was updated successfully, but these errors were encountered: