Closed
Description
TypeScript Version:
1.8.7
Code
function func(val: "Test") {
console.log(val);
}
func("Test");
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?