mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-06-10 18:04:18 -05:00
Loosen up the first argument type for String.raw
The [String.raw spec](https://tc39.es/ecma262/#sec-string.raw) uses just the `raw` property of its first argument, which is a useful way of using it in user-defined tag functions to do the work of interleaving strings and values as well as converting the values to strings. Fixes #43609.
This commit is contained in:
10
src/lib/es2015.core.d.ts
vendored
10
src/lib/es2015.core.d.ts
vendored
@@ -487,11 +487,13 @@ interface StringConstructor {
|
||||
fromCodePoint(...codePoints: number[]): string;
|
||||
|
||||
/**
|
||||
* String.raw is intended for use as a tag function of a Tagged Template String. When called
|
||||
* as such the first argument will be a well formed template call site object and the rest
|
||||
* parameter will contain the substitution values.
|
||||
* String.raw is usually used as a tag function of a Tagged Template String. When called as
|
||||
* such, the first argument will be a well formed template call site object and the rest
|
||||
* parameter will contain the substitution values. It can also be called directly, for example,
|
||||
* to interleave strings and values from your own tag function, and in this case the only thing
|
||||
* it needs from the first argument is the raw property.
|
||||
* @param template A well-formed template string call site representation.
|
||||
* @param substitutions A set of substitution values.
|
||||
*/
|
||||
raw(template: TemplateStringsArray, ...substitutions: any[]): string;
|
||||
raw(template: { raw: readonly string[] | ArrayLike<string>}, ...substitutions: any[]): string;
|
||||
}
|
||||
|
||||
6
tests/baselines/reference/stringRawType.js
Normal file
6
tests/baselines/reference/stringRawType.js
Normal file
@@ -0,0 +1,6 @@
|
||||
//// [stringRawType.ts]
|
||||
String.raw({ raw: ["foo", "bar", "baz"] }, 1, 2);
|
||||
|
||||
|
||||
//// [stringRawType.js]
|
||||
String.raw({ raw: ["foo", "bar", "baz"] }, 1, 2);
|
||||
7
tests/baselines/reference/stringRawType.symbols
Normal file
7
tests/baselines/reference/stringRawType.symbols
Normal file
@@ -0,0 +1,7 @@
|
||||
=== tests/cases/compiler/stringRawType.ts ===
|
||||
String.raw({ raw: ["foo", "bar", "baz"] }, 1, 2);
|
||||
>String.raw : Symbol(StringConstructor.raw, Decl(lib.es2015.core.d.ts, --, --))
|
||||
>String : Symbol(String, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --), Decl(lib.es2015.core.d.ts, --, --), Decl(lib.es2015.iterable.d.ts, --, --) ... and 1 more)
|
||||
>raw : Symbol(StringConstructor.raw, Decl(lib.es2015.core.d.ts, --, --))
|
||||
>raw : Symbol(raw, Decl(stringRawType.ts, 0, 12))
|
||||
|
||||
15
tests/baselines/reference/stringRawType.types
Normal file
15
tests/baselines/reference/stringRawType.types
Normal file
@@ -0,0 +1,15 @@
|
||||
=== tests/cases/compiler/stringRawType.ts ===
|
||||
String.raw({ raw: ["foo", "bar", "baz"] }, 1, 2);
|
||||
>String.raw({ raw: ["foo", "bar", "baz"] }, 1, 2) : string
|
||||
>String.raw : (template: { raw: readonly string[] | ArrayLike<string>; }, ...substitutions: any[]) => string
|
||||
>String : StringConstructor
|
||||
>raw : (template: { raw: readonly string[] | ArrayLike<string>; }, ...substitutions: any[]) => string
|
||||
>{ raw: ["foo", "bar", "baz"] } : { raw: string[]; }
|
||||
>raw : string[]
|
||||
>["foo", "bar", "baz"] : string[]
|
||||
>"foo" : "foo"
|
||||
>"bar" : "bar"
|
||||
>"baz" : "baz"
|
||||
>1 : 1
|
||||
>2 : 2
|
||||
|
||||
3
tests/cases/compiler/stringRawType.ts
Normal file
3
tests/cases/compiler/stringRawType.ts
Normal file
@@ -0,0 +1,3 @@
|
||||
// @target: es6
|
||||
|
||||
String.raw({ raw: ["foo", "bar", "baz"] }, 1, 2);
|
||||
Reference in New Issue
Block a user