如何在 TypeScript 中执行字符串插值?

How to perform string interpolation in TypeScript?

C# 使用字符串插值

int value = 100;
Console.WriteLine($"The size is {value}.");

输出:

The size is 100.

如何在 TypeScript 中做同样的事情?

在JavaScript中你可以使用template literals:

Template literals are literals delimited with backticks (`)

let value = 100;
console.log(`The size is ${ value }`);

就用特殊的`

var lyrics = 'Never gonna give you up';
var html = `<div>${lyrics}</div>`;

您可以查看更多示例here