@adorkable/eunomia-typescript
    Preparing search index...

    Function makeEnum

    • makeEnum: Typescript utility for making "more useful" enums, based on the help of Stack Overflow member jcalz: https://stackoverflow.com/a/79760980/96153

      Type Parameters

      • const EnumRecord extends Record<string, string>

      Parameters

      Returns {
          map: MapWithNoDuplicateValues<string, string, EnumRecord>;
          type: EnumRecord[keyof EnumRecord];
          values: EnumRecord[keyof EnumRecord][];
      }

      const example = makeEnum({
      Dead: "Beef",
      Hello: "World",
      Lorum: "Ipsum"
      })

      export const Example = example.map
      // Result:
      // const Example: {
      // readonly Dead: "Beef";
      // readonly Hello: "World";
      // readonly Lorum: "Ipsum";
      // }
      // Useful for value references: const value = Example.Hello

      export const ExampleValues = example.values
      // Result:
      // const ExampleValues: readonly ("Beef" | "World" | "Ipsum")[]
      // Useful for iterating over all values or runtime testing valid values

      export type ExampleType = typeof example.type
      // Result:
      // type ExampleType = "Beef" | "World" | "Ipsum"
      // Useful for type checking when defining signatures of other types, functions, etc