TypeScript/tests/baselines/reference/templateLiteralsInTypes.types
Eli Barzilay 635f5bdf8c Some tweaks for backtick strings
1. `getRawLiteral()`: barf if `currentSourceFile` is missing, since if
   it is, then the following `getSourceTextOfNodeFromSourceFile` will
   return a bogus `""`.

2. One `||` -> `??` change.

3. `backtickQuoteEscapedCharsRegExp`: escape the usual control
   characters except for a simple LF.  This code does get used to
   generate backtick strings when `rawText` is not given, and not
   escaping things like TAB characters can get mangled by editor
   settings.  Worse, not escaping a CRLF and putting it verbatim in sthe
   string source will interpret it as LF, so add a special case for
   escaping these as `\r\n`.
   Added test.

Related to #44313 and #40625.
2021-08-05 05:45:34 -04:00

19 lines
723 B
Plaintext

=== tests/cases/compiler/templateLiteralsInTypes.ts ===
const f = (hdr: string, val: number) => `${hdr}:\t${val}\r\n` as `${string}:\t${number}\r\n`;
>f : (hdr: string, val: number) => `${string}:\t${number}\r\n`
>(hdr: string, val: number) => `${hdr}:\t${val}\r\n` as `${string}:\t${number}\r\n` : (hdr: string, val: number) => `${string}:\t${number}\r\n`
>hdr : string
>val : number
>`${hdr}:\t${val}\r\n` as `${string}:\t${number}\r\n` : `${string}:\t${number}\r\n`
>`${hdr}:\t${val}\r\n` : `${string}:\t${number}\r\n`
>hdr : string
>val : number
f("x").foo;
>f("x").foo : any
>f("x") : `${string}:\t${number}\r\n`
>f : (hdr: string, val: number) => `${string}:\t${number}\r\n`
>"x" : "x"
>foo : any