枚举不是类型,而是对象。它的值也是值,因此您需要将它们分配给常量。
enum languages {
FoldingRange,
FoldingContext,
FoldingRangeKind
}
export const FoldingRange = languages.FoldingRange;
export const FoldingContext = languages.FoldingContext;
export const FoldingRangeKind = languages.FoldingRangeKind;
interface iLanguages {
FoldingRange: 0,
FoldingContext: 1,
}
export type FoldingRange = iLanguages["FoldingRange"];
export type FoldingContext = iLanguages["FoldingContext"];
export type FoldingRangeKind = languages.FoldingRangeKind;
这是随后编译的内容(
playground
). 希望这能为你解决问题。
var languages;
(function (languages) {
languages[languages["FoldingRange"] = 0] = "FoldingRange";
languages[languages["FoldingContext"] = 1] = "FoldingContext";
languages[languages["FoldingRangeKind"] = 2] = "FoldingRangeKind";
})(languages || (languages = {}));
export const FoldingRange = languages.FoldingRange;
export const FoldingContext = languages.FoldingContext;
export const FoldingRangeKind = languages.FoldingRangeKind;