是否可以在没有 const 枚举的情况下内联字符串?

Is it possible to inline string without const enum?

我想导出字符串 contsnt,但它会在所有使用它的地方内联,并且不会创建变量。我知道 const enum:

是可能的
const enum SomeEnum {
    SOME_VALUE = "SOME_VALUE"
}

alert(SomeEnum.SOME_VALUE);

编译成

"use strict";
alert("SOME_VALUE" /* SOME_VALUE */);

但我有兴趣对值进行无点访问,我。 e.我要写

alert(SOME_VALUE);

我希望它被编译成同样的东西。

如何声明 SOME_VALUE 存档?

截至 2020-09 年,您不能,

在 Typescript GitHub 存储库中讨论了这样一个特性——内联常量:https://github.com/microsoft/TypeScript/issues/3964

更新:现在那个问题got closed

given the feedback so far and the risk of the feature, it's safe to say this isn't happening

那么,可能永远不会。