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: 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.
The text was updated successfully, but these errors were encountered:
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
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
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
TypeScript Version: 2.4.0
Code
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.
The text was updated successfully, but these errors were encountered: