Closed sugoroku-y closed 1 year ago
@Kingwl you might be interested in this one.
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`;
Also, this doesnât occur when the \u
 follows a substitution.
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.
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: https://github.com/microsoft/TypeScript/pull/41030
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 https://github.com/tc39/ecma262/commit/138c9efc5460c22e175007ba2608b2c4238e11ef.
Ahhhh Okay. Got the point. Thanks.
I think that dealing with octal escapes in all strings #396 should be done before dealing with tagged templates as an exception...
:wave: 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
:x: Failed: -
Hexadecimal digit expected.
Version | Reproduction Outputs |
---|---|
4.2.2, 4.3.2, 4.4.2, 4.5.2, 4.6.2 |
:x: Failed: -
|
Hi, is this issue being worked on? I would like to look into this as a first issue.
@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 string
s and undefined
s, intersected with {raw: ...}
. of equal-sized tuple of string
s. This type should be backwards compatible.
Bug Report
đ Search Terms
String.raw
đ Version & Regression Information
⯠Playground Link
Playground link with relevant code
đ» Code
đ Actual behavior
Error reported:
error TS1125: Hexadecimal digit expected.
đ Expected behavior
Complete transpile