Skip to content

\u in String.rawΒ #42887

Description

Bug Report

πŸ”Ž Search Terms

String.raw

πŸ•— Version & Regression Information

  • This is the behavior in every version I tried, and I reviewed the FAQ for entries about String.raw

⏯ Playground Link

Playground link with relevant code

πŸ’» Code

String.raw`adc\def\ghi\jkl\mno\pqr\st\uvw\xyz`

πŸ™ Actual behavior

Error reported: error TS1125: Hexadecimal digit expected.

πŸ™‚ Expected behavior

Complete transpile

Activity

  1. DanielRosenwasser commented on Feb 20, 2021

    @DanielRosenwasser
    Member

    Wenlu Wang (@Kingwl) you might be interested in this one.

  2. ExE-Boss commented on Feb 20, 2021

    @ExE-Boss
    Contributor

    It’s not just String.raw, this applies to all tagged template literals, whereΒ theΒ top‑level TemplateStringArray containsΒ undefined forΒ anΒ unknownΒ escape, soΒ thisΒ should alsoΒ update TemplateStringsArray:

    const taggedTemplate = (template: TemplateStringsArray, ...substitutions: unknown[]) => {
    	console.log(template, substitutions);
    }
    
    // Logs:
    // [
    // 	undefined, "bar", undefined,
    // 	raw: [ "foo\\uvar", "bar", "baz\\u" ]
    // ]
    // [ 123, 456 ]
    taggedTemplate`foo\uvar${123}bar${456}baz\u`;

    Workbench Repro


    Also, this doesn’t occur when theΒ \uΒ follows aΒ substitution.

  3. Kingwl commented on Feb 20, 2021

    @Kingwl
    Contributor

    It’s not just String.raw, this applies to all tagged template literals

    Sorry I'm not 100% sure what your means.
    But seems the runtime behavior is as expected.

    image

    The current problem is falsely alarm.

    Here's some context:

    And I have found an PR who try to fix a part of the alarm: #41030

  4. ExE-Boss commented on Feb 20, 2021

    @ExE-Boss
    Contributor

    TheΒ definition ofΒ TemplateStringArray shouldΒ include undefined inΒ theΒ top‑level indexΒ signature, whichΒ should beΒ fixed alongsideΒ this toΒ correctlyΒ describe theΒ runtimeΒ behaviour asΒ ofΒ tc39/ecma262@138c9ef.

  5. Kingwl commented on Feb 20, 2021

    @Kingwl
    Contributor

    Ahhhh Okay. Got the point. Thanks.

  6. elibarzilay commented on Jun 3, 2021

    @elibarzilay
    Contributor

    I think that dealing with octal escapes in all strings #396 should be done before dealing with tagged templates as an exception...

  7. typescript-bot commented on Apr 14, 2022

    @typescript-bot
    Contributor

    πŸ‘‹ Hi, I'm the Repro bot. I can help narrow down and track compiler bugs across releases! This comment reflects the current state of this repro running against the nightly TypeScript.


    Comment by ExE Boss (@ExE-Boss)

    ❌ Failed: -

    • Hexadecimal digit expected.

    Historical Information
    Version Reproduction Outputs
    4.2.2, 4.3.2, 4.4.2, 4.5.2, 4.6.2

    ❌ Failed: -

    • Hexadecimal digit expected.

  8. bentongxyz commented on Apr 28, 2022

    @bentongxyz
    Contributor

    Hi, is this issue being worked on? I would like to look into this as a first issue.

  9. reverofevil commented on May 22, 2022

    @reverofevil

    Almost created a duplicate to this issue.

    The proposal was here, normative section in ECMA-262 here.

  10. reverofevil commented on May 22, 2022

    @reverofevil

    ExE Boss (@ExE-Boss)

    The definition of TemplateStringArray should include undefined in the top‑level index signature,

    I'm afraid such a change will break existing code. undefined is there only if a part of string template contains invalid escape characters, and this information is available in compile-time. I'd suggest replacing TemplateStringsArray with a readonly tuple of strings and undefineds, intersected with {raw: ...}. of equal-sized tuple of strings. This type should be backwards compatible.

  11. locked as resolved and limited conversation to collaborators on Oct 21, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugA bug in TypeScriptGood First IssueWell scoped, documented and has the green lightHas ReproThis issue has compiler-backed repros: https://aka.ms/ts-reprosHelp WantedYou can do this

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions