转义换行符时键入无效字符



我有一个简单的方法,只需将一堆字符串连接起来,并对其进行可读格式设置。

info() {
return    "x:      " + this.xpos.toString() + "n" 
+ "y:      " + this.ypos.toString() + "n" 
+ "width:  " + this.width.toString() + "n" 
+ "height: " + this.height.toString() + "n";
}

我知道代码本身并不惊人,但当我运行tsc时,我会得到以下错误:

cli.ts:32:54 - error TS1127: Invalid character.

对于存在以转义换行符的所有行,都会发生这种情况。我需要做什么来逃离TS中的换行符?

在Typescript中,您不需要就可以像在Python等语言中那样将一长行代码分解为多行。如果删除它们,代码将重新编译。

也许模板字符串可以帮助组织一下?

最新更新