转义换行符时打字稿无效字符?
Typescript invalid character when escaping newline?
我有一个简单的方法,我只是连接一堆字符串并将其格式化为可读性。
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 这样的语言中那样将一长行代码分成多行。如果删除它们,您的代码将再次编译。
也许 template strings 可以帮助组织一下?
我有一个简单的方法,我只是连接一堆字符串并将其格式化为可读性。
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 这样的语言中那样将一长行代码分成多行。如果删除它们,您的代码将再次编译。
也许 template strings 可以帮助组织一下?