I have a simple method where I just concatenate a bunch of strings and format it somewhat readably.
info() {
return "x: " + this.xpos.toString() + "\n" \
+ "y: " + this.ypos.toString() + "\n" \
+ "width: " + this.width.toString() + "\n" \
+ "height: " + this.height.toString() + "\n";
}
I'm aware the code itself isn't amazing, but when I run tsc
, I get the following error:
cli.ts:32:54 - error TS1127: Invalid character.
This occurs for all the lines where there is a \\
to escape the newline. What do I need to do to escape a newline in TS?
In Typescript, you don't need the \\
to be able to break a long line of code into multiple lines like you would in a language like Python. If you remove them, your code will compile again.
Perhaps template strings would help organize this a bit?
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.