-
> Enums is going to make your TypeScript code not work in a future where TypeScript code can be run with Node.js
Apparently they're planning on adding a tsconfig option to disallow these Node-incompatible features as well [1].
Using this limited subset of TS also allows your code to compile with Bloomberg's ts-blank-space, which literally just replaces type declarations with blank spaces [2].
[1] https://github.com/microsoft/TypeScript/issues/59601
[2] https://bloomberg.github.io/ts-blank-space/
-
CodeRabbit
CodeRabbit: AI Code Reviews for Developers. Revolutionize your code reviews with AI. CodeRabbit offers PR summaries, code walkthroughs, 1-click suggestions, and AST-based analysis. Boost productivity and code quality across all major languages with each PR.
-
After almost a decade of TypeScript my recommendation is to not use TypeScript enums.
Enums is going to make your TypeScript code not work in a future where TypeScript code can be run with Node.js or in browser when typings are added to JavaScript[1]
Enums results in runtime code and in most cases you really want type enums. Use `type State = "Active" | "Inactive"` and so on instead. And if you really want an closed-ended object use `const State = { Active: 1, Inactive: 0 } as const`
[1] https://github.com/tc39/proposal-type-annotations
-
ts-blank-space
A small, fast, pure JavaScript type-stripper that uses the official TypeScript parser.
> Enums is going to make your TypeScript code not work in a future where TypeScript code can be run with Node.js
Apparently they're planning on adding a tsconfig option to disallow these Node-incompatible features as well [1].
Using this limited subset of TS also allows your code to compile with Bloomberg's ts-blank-space, which literally just replaces type declarations with blank spaces [2].
[1] https://github.com/microsoft/TypeScript/issues/59601
[2] https://bloomberg.github.io/ts-blank-space/
-
I've found this to be quite ergonomic and functional:
https://github.com/photostructure/fs-metadata/blob/main/src/...
Usage:
export const Directions = stringEnum("North", "South", "East", "West")