TypeScript 是否具有变量名称转义功能,例如 Scala 中用于文字标识符的反引号?

Does TypeScript has variable names escaping feature like backticks in Scala for literal identifiers?

TypeScript 是否具有变量名称转义功能,例如 Scala 中用于文字标识符的反引号:

`0029-otherwise-illegal-scala-literal`

请参阅 Need clarification on Scala literal identifiers (backticks)

中的 Scala 解释

您可以在 https://github.com/Microsoft/TypeScript/blob/master/doc/spec.md#8.2

找到规范

2.2.2节告诉你

The PropertyName production from the ECMAScript grammar is reproduced below:

  PropertyName:    LiteralPropertyName    ComputedPropertyName

  LiteralPropertyName:    IdentifierName    StringLiteral    NumericLiteral

  ComputedPropertyName:    [ AssignmentExpression ]

A property name can be any identifier (including a reserved word), a string literal, a numeric literal, or a computed property name. String literals may be used to give properties names that are not valid identifiers, such as names containing blanks. Numeric literal property names are equivalent to string literal property names with the string representation of the numeric literal, as defined in the ECMAScript specification.

这包括字符串文字。

您可以将 属性 声明为字符串文字:

class MyClass {
  "return" = 1;
}

你可以用方括号访问它

let myinstance = new MyClass()
let one = myinstance["return"]