字符串插值无法正确呈现

时间:2021-02-23 10:09:57

标签: javascript typescript-generics

我是 TypeScript 的新手,我正在尝试学习 ${} 占位符并且我正在运行这个 helloworld.ts

enter image description here

但我的输出是占位符的字面翻译:

enter image description here

2 个答案:

答案 0 :(得分:3)

你必须使用反引号`。

const message: string = "My text";
console.log(`This will works ${message}`);

答案 1 :(得分:0)

没关系,我已经弄清楚了,您需要使用反引号而不是单引号。

enter image description here