Let's deprecate enum
s!
The typescript team has added --erasableSyntaxOnly
to their compiler, which disables the use of enum
s. This is for compatibility with running .ts
files directly from a runtime without a build step. You can read more about it here from Matt Pocock.
I've written this library to give the feel of enum
s, but in a way that doesn't require a build step.
import { numEnum, stringEnum } from "@tyler/enum";
const colors = numEnum(["red", "green", "blue"]);
const animals = stringEnum(["cat", "dog", "bird"]);
console.log(colors.red); // 0
console.log(colors.green); // 1
console.log(colors.blue); // 2
console.log(animals.cat); // cat
console.log(animals.dog); // dog
console.log(animals.bird); // bird
If you're looking for type errors on comparisons between differently named enums: