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

Parse backtick delineated string without interpolation as string literals #18109

Closed
ericbf opened this issue Aug 29, 2017 · 2 comments
Closed
Labels
Duplicate An existing issue was already created

Comments

@ericbf
Copy link
Contributor

ericbf commented Aug 29, 2017

TypeScript Version: 2.4.0

Code

let test: `a` | `b`

Expected behavior:
test will be a variable of type "a" | "b", like when single quotes or double quotes are used.

Actual behavior:
It does not compile, giving various errors.

Justification:
We like to enforce the use of template strings instead of concatenation, but that leaves us with a mixture of backtick strings and either double or single quote strings. Ideally we would enforce just one type of quote throughout our projects and leave it at that. In order to utilize the power of template strings, we should obviously enforce only backticks for strings.

The problem now is that the compiler doesn't accurately parse strings delineated by backticks. When backtick delineated strings don't have any interpolation in them, the compiler should be able to recognize that they are just literal strings and should use them for type inference and everything else.

@ericbf ericbf changed the title Parse backticks correctly when using for all strings (for consistency) Parse backtick delineated string without interpolation as string literals Aug 29, 2017
@mhegazy mhegazy added Suggestion An idea for TypeScript Awaiting More Feedback This means we'd like to hear from more people who would be helped by this feature labels Aug 29, 2017
@DanielRosenwasser DanielRosenwasser added the Domain: Literal Types Unit types including string literal types, numeric literal types, Boolean literals, null, undefined label Aug 29, 2017
@ericbf
Copy link
Contributor Author

ericbf commented Sep 1, 2017

I'd argue that this is a duplicate of #16592 and that that particular issue wasn't fully fixed by #17704.

@DanielRosenwasser

We should just allow people to use NoSubstitutionTemplates the way that they're allowed to use regular strings.

That also includes being able to put NoSubstitutionTemplates as types, and anywhere else that string literals can be used.

@mhegazy mhegazy added Duplicate An existing issue was already created and removed Awaiting More Feedback This means we'd like to hear from more people who would be helped by this feature Domain: Literal Types Unit types including string literal types, numeric literal types, Boolean literals, null, undefined Suggestion An idea for TypeScript labels Sep 5, 2017
@mhegazy
Copy link
Contributor

mhegazy commented Sep 5, 2017

closing in favor of #16592. thanks.

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

3 participants