mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-02-06 02:33:53 -06:00
Check for symbol types in template expressions
This commit is contained in:
parent
c12fc0d6c3
commit
fc08ff5a36
@ -19361,7 +19361,9 @@ namespace ts {
|
||||
// A place where we actually *are* concerned with the expressions' types are
|
||||
// in tagged templates.
|
||||
forEach(node.templateSpans, templateSpan => {
|
||||
checkExpression(templateSpan.expression);
|
||||
if (maybeTypeOfKind(checkExpression(templateSpan.expression), TypeFlags.ESSymbolLike)) {
|
||||
error(templateSpan.expression, Diagnostics.Type_0_cannot_be_converted_to_type_1, typeToString(esSymbolType), typeToString(stringType));
|
||||
}
|
||||
});
|
||||
|
||||
return stringType;
|
||||
|
||||
@ -0,0 +1,21 @@
|
||||
tests/cases/compiler/noImplicitSymbolToString.ts(6,30): error TS2352: Type 'symbol' cannot be converted to type 'string'.
|
||||
tests/cases/compiler/noImplicitSymbolToString.ts(7,30): error TS2469: The '+' operator cannot be applied to type 'symbol'.
|
||||
tests/cases/compiler/noImplicitSymbolToString.ts(8,8): error TS2469: The '+=' operator cannot be applied to type 'symbol'.
|
||||
|
||||
|
||||
==== tests/cases/compiler/noImplicitSymbolToString.ts (3 errors) ====
|
||||
// Fix #19666
|
||||
|
||||
let symbol!: symbol;
|
||||
let str = "hello ";
|
||||
|
||||
const templateStr = `hello ${symbol}`;
|
||||
~~~~~~
|
||||
!!! error TS2352: Type 'symbol' cannot be converted to type 'string'.
|
||||
const appendStr = "hello " + symbol;
|
||||
~~~~~~
|
||||
!!! error TS2469: The '+' operator cannot be applied to type 'symbol'.
|
||||
str += symbol;
|
||||
~~~~~~
|
||||
!!! error TS2469: The '+=' operator cannot be applied to type 'symbol'.
|
||||
|
||||
18
tests/baselines/reference/noImplicitSymbolToString.js
Normal file
18
tests/baselines/reference/noImplicitSymbolToString.js
Normal file
@ -0,0 +1,18 @@
|
||||
//// [noImplicitSymbolToString.ts]
|
||||
// Fix #19666
|
||||
|
||||
let symbol!: symbol;
|
||||
let str = "hello ";
|
||||
|
||||
const templateStr = `hello ${symbol}`;
|
||||
const appendStr = "hello " + symbol;
|
||||
str += symbol;
|
||||
|
||||
|
||||
//// [noImplicitSymbolToString.js]
|
||||
// Fix #19666
|
||||
var symbol;
|
||||
var str = "hello ";
|
||||
var templateStr = "hello " + symbol;
|
||||
var appendStr = "hello " + symbol;
|
||||
str += symbol;
|
||||
21
tests/baselines/reference/noImplicitSymbolToString.symbols
Normal file
21
tests/baselines/reference/noImplicitSymbolToString.symbols
Normal file
@ -0,0 +1,21 @@
|
||||
=== tests/cases/compiler/noImplicitSymbolToString.ts ===
|
||||
// Fix #19666
|
||||
|
||||
let symbol!: symbol;
|
||||
>symbol : Symbol(symbol, Decl(noImplicitSymbolToString.ts, 2, 3))
|
||||
|
||||
let str = "hello ";
|
||||
>str : Symbol(str, Decl(noImplicitSymbolToString.ts, 3, 3))
|
||||
|
||||
const templateStr = `hello ${symbol}`;
|
||||
>templateStr : Symbol(templateStr, Decl(noImplicitSymbolToString.ts, 5, 5))
|
||||
>symbol : Symbol(symbol, Decl(noImplicitSymbolToString.ts, 2, 3))
|
||||
|
||||
const appendStr = "hello " + symbol;
|
||||
>appendStr : Symbol(appendStr, Decl(noImplicitSymbolToString.ts, 6, 5))
|
||||
>symbol : Symbol(symbol, Decl(noImplicitSymbolToString.ts, 2, 3))
|
||||
|
||||
str += symbol;
|
||||
>str : Symbol(str, Decl(noImplicitSymbolToString.ts, 3, 3))
|
||||
>symbol : Symbol(symbol, Decl(noImplicitSymbolToString.ts, 2, 3))
|
||||
|
||||
26
tests/baselines/reference/noImplicitSymbolToString.types
Normal file
26
tests/baselines/reference/noImplicitSymbolToString.types
Normal file
@ -0,0 +1,26 @@
|
||||
=== tests/cases/compiler/noImplicitSymbolToString.ts ===
|
||||
// Fix #19666
|
||||
|
||||
let symbol!: symbol;
|
||||
>symbol : symbol
|
||||
|
||||
let str = "hello ";
|
||||
>str : string
|
||||
>"hello " : "hello "
|
||||
|
||||
const templateStr = `hello ${symbol}`;
|
||||
>templateStr : string
|
||||
>`hello ${symbol}` : string
|
||||
>symbol : symbol
|
||||
|
||||
const appendStr = "hello " + symbol;
|
||||
>appendStr : string
|
||||
>"hello " + symbol : string
|
||||
>"hello " : "hello "
|
||||
>symbol : symbol
|
||||
|
||||
str += symbol;
|
||||
>str += symbol : string
|
||||
>str : string
|
||||
>symbol : symbol
|
||||
|
||||
8
tests/cases/compiler/noImplicitSymbolToString.ts
Normal file
8
tests/cases/compiler/noImplicitSymbolToString.ts
Normal file
@ -0,0 +1,8 @@
|
||||
// Fix #19666
|
||||
|
||||
let symbol!: symbol;
|
||||
let str = "hello ";
|
||||
|
||||
const templateStr = `hello ${symbol}`;
|
||||
const appendStr = "hello " + symbol;
|
||||
str += symbol;
|
||||
Loading…
x
Reference in New Issue
Block a user