#TypeScript—I’m trying out this pattern for “enums” with object values:
const Heading = {
Part: {
key: 'Part',
level: 1,
},
Chapter: {
key: 'Chapter',
level: 2,
},
Section: {
key: 'Section',
level: 3,
},
} as const;
// Discriminated union!
type HeadingType = PropValues<typeof Heading>;
// Name could be `Heading` but that trips up TS language server in
// some cases.
type PropValues<Obj> = Obj[keyof Obj];
Related: https://exploringjs.com/tackling-ts/ch_enum-alternatives.html