On 3/20/2020 4:44 AM, Max Paperno wrote:

Obviously one could come up with a little helper function/object which makes this prettier. And you could make it auto-assign incremental values if one isn't provided in the "constructor" (like a C enum does)

Err, sorry, I meant a helper object which also provides reverse mapping from symbol to name.

Something like

var Enum;
(function (Enum) {
    Enum[Enum["A"] = 0] = "A";
})(Enum || (Enum = {}));

var a = Enum.A;
var nameOfA = Enum[a]; // "A"

See:
https://www.typescriptlang.org/docs/handbook/enums.html#reverse-mappings

Also their enum type implementation in general seems nice.

-Max
_______________________________________________
Interest mailing list
Interest@qt-project.org
https://lists.qt-project.org/listinfo/interest

Reply via email to