How trans nested enum to map?

enum Armor {
	Back;
}

enum Weapon {
       Sword;
}

enum Equipment {
       Armor(a: Armor);
       Weapon(w: Weapon);
}

want to iterator Equipment get result map:

{
Back,
Sword
}

or how merge enum keys? like typescript union type Merge = ItemId & Test;

use castledb custom type equipment,but i need iterator equipment create equipment slot

curretly use marco merge enum,If you have a better idle please give it to me.

@:build(tools.EnumBuildingMacro.union(
  Armor,
  Weapon,
))
enum abstract TestMerge(String) to String {}

Haxe doesn’t have a direct equivalent to TypeScript’s more advanced typing features. Enum abstracts might be the closest you’ll get.

That said, if you’re willing to dig into macros, almost anything becomes possible. I forget if generic macros work on enum abstracts, but if they did they could probably reproduce the feature you’re looking for.

Sadly, they aren’t well-documented. The manual doesn’t even mention that you can use the name Rest to take a variable number of type params. So then you could declare a Union<Rest> type with a build macro attached, and when the user asked for Union<Armor, Weapon>, you’d generate that type.

I don’t have time to go over the process in depth, but if you’re willing to learn from source code, here’s where Echoes builds View classes.