@noracodes i’m wondering if this is broadly the pattern you’re looking for or if there’s more here that i am missing?
class Pokémon {
#type
constructor(data) {
Object.assign(this, data)
}
get type() { return this.#type }
set type(x) {
if (!["Normal", "Fighting", "Flying", "Poison", "Ground", "Rock", "Bug", "Ghost", "Steel", "Fire", "Grass", "Water", "Electric", "Psychic", "Ice", "Dragon", "Dark", "Fairy"].includes(x)) throw new RangeError("Invalid type");
else this.#type = x;
}
}
new Pokémon({type: "Fire"});
new Pokémon(JSON.parse("{\"type\": \"Fire\"}"));
new Pokémon({type: "Bird"}); // error