ubiquity / ts-template

A template repository for all @ubiquity projects.
2 stars 24 forks source link

`const enum` > `enum` #48

Closed Keyrxng closed 5 months ago

Keyrxng commented 5 months ago

Furthering a discussion between myself and @gentlementlegen during code review regarding the usage of const enums vs Enums and which of the two should it be?


I'm against the usage of Enums as they are not an extension of JS which TS should be. They introduce more JS than compared to a const enum and are not considered a best practice in TS as far as I understand things.

https://www.typescriptlang.org/docs/handbook/enums.html#const-enums

Objects vs Enums In modern TypeScript, you may not need an enum when an object with as const could suffice: ...

The biggest argument in favour of this format over TypeScript’s enum is that it keeps your codebase aligned with the state of JavaScript, and when/if enums are added to JavaScript then you can move to the additional syntax.


I'm not saying replace all Enums across the org but when/if possible we should use const enums.

Penny for your thoughts?

_original context https://github.com/ubiquibot/command-start-stop/pull/1#discussion_r1634255389_

0x4007 commented 5 months ago

https://github.com/ubiquibot/command-start-stop/pull/1/files/03075e2a9789fe3134d0413e32aa51561b521fd1..0dcd24329b904c7b050e3f7c2fdaf84c7b48fc4c#r1635324076

ubiquibot[bot] commented 5 months ago
# Issue was not closed as completed. Skipping.
ubiquity-os-main[bot] commented 5 months ago
# Issue was not closed as completed. Skipping.