no-closed-literal-union
@azure-tools/typespec-azure-core/no-closed-literal-union
Azure services favor extensible enums to avoid breaking changes as new enum values are added. When using a union of only string or numeric literals it is the equivalent to a closed enum.
Adding the base scalar(string
, int32
, int64
, etc.) as a variant to the union makes it extensible.
❌ Incorrect
union PetKind { Cat: "cat", Dog: "dog",}
model Pet { kind: "cat" | "dog";}
✅ Correct
union PetKind { Cat: "Cat", Dog: "Dog", string,}
model Pet { kind: "cat" | "dog" | string;}