[Interest] Will Qt6 end this enum issue? (or even 5.15?)

Max Paperno max-l at wdg.us
Fri Mar 20 09:56:01 CET 2020


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


More information about the Interest mailing list