Skip to content

Parse backtick delineated string without interpolation as string literals #18109

@ericbf

Description

@ericbf

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    DuplicateAn existing issue was already created

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions