Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unary string literal types don't seem to work when applied to function arguments #7541

Closed
malibuzios opened this issue Mar 16, 2016 · 1 comment
Labels
Duplicate An existing issue was already created

Comments

@malibuzios
Copy link

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?

@malibuzios 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
@malibuzios
Copy link
Author

OK, just found out this is a duplicate of #6143 and #6991. Closing.

@RyanCavanaugh RyanCavanaugh added the Duplicate An existing issue was already created label May 5, 2016
@microsoft microsoft locked and limited conversation to collaborators Jun 19, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Duplicate An existing issue was already created
Projects
None yet
Development

No branches or pull requests

2 participants