Just because Enums are bad in type/javascript doesn't mean there are bad at every other language. In fact, pretty much every language implements Enums much better.
@maran2347 I was focusing on typescript in the video in pretty much every other language they are super useful I'll adjust the title to stop the confusion
The point of enums, in any language, is to avoid people passing strings around. Problematic for refactoring or long term maintenance in any even moderate sized code bases.
For me, enums are definitely better than to pass strings around. Refactoring is a lot easier - how do you refactor a code when you pass around plain strings? Lets say, your "warning" log level becomes "warn" for some reason. You go through full codebase and change it by hand where needed / where typescript yells at you? Yeah, no, thanks. It has some caveats, for sure, but still looks like a lot better option for me.
why would you use a string when you already have defined a name? isn't this just like 1 step forward two steps back? although the conversion by typescript is weird but what you did in the last example using a simple object could have been used as Levels.DEBUG.
That stops you from using Levels.DEBUG the power of this is that you can use the string and the type interchangeably rather than being limited to one or the other
Will you stop using enums after this video?
Just because Enums are bad in type/javascript doesn't mean there are bad at every other language. In fact, pretty much every language implements Enums much better.
@maran2347 I was focusing on typescript in the video in pretty much every other language they are super useful I'll adjust the title to stop the confusion
After watching I would immediately stop using typescript. I'm glad I made this decision 3 years ago.
I will stop using TypeScript instead.
@@Tekay37 lol 😆
The point of enums, in any language, is to avoid people passing strings around. Problematic for refactoring or long term maintenance in any even moderate sized code bases.
enum is just great
What’s wrong with imports? Also, doesn’t passing the string defeat the point of using an enum
Why do want to use strings instead of just referring to the enum name for every time you want to access a member?
For me, enums are definitely better than to pass strings around. Refactoring is a lot easier - how do you refactor a code when you pass around plain strings? Lets say, your "warning" log level becomes "warn" for some reason. You go through full codebase and change it by hand where needed / where typescript yells at you? Yeah, no, thanks.
It has some caveats, for sure, but still looks like a lot better option for me.
why would you use a string when you already have defined a name? isn't this just like 1 step forward two steps back? although the conversion by typescript is weird but what you did in the last example using a simple object could have been used as Levels.DEBUG.
The fact that you can use both string and the object itself is where the power comes from rather than being limited to just using the enum itself
But isn’t that literally the purpose of enums?…. To only expect and use those values
The whole purpose of ENUMS is to prevent passing arbitrary values but only one of the Enum types!
Honestly, i just make my own string litteral type instead, it works better. I do it like this:
type Direction = “Up” | “Down” | “Left” | “Right”;
Or just use enum type literals….
Bro is complaining that enums work like they’re supposed to. Not being able to pass in the raw value is the entire purpose.
that's actually counter-intuitive, thanks for explaining
How about `type Foo = "one"|"two"|"three"`. I like enums, to me it looks like creating problems where they do not exist😂.
That stops you from using Levels.DEBUG the power of this is that you can use the string and the type interchangeably rather than being limited to one or the other
Rust enums are the best. Typescript enums should learn from that (sum types supremacy)
title should say "Typescript"
I've changed it now to avoid confusion
@@Computeshorts love you bud
lol enums don't even exist in golang
First mistake: use typescript to do pretty much anything.
I don’t like TS = bad developer
Use RUST and LOVE youe ENUMS
There is so much hype around Rust I never managed to check it out but I plan to this year. Will probably change my mind on enums then 🤣
@@Computeshorts ua-cam.com/video/Epwlk4B90vk/v-deo.html
Title should be stop using typescript
Lol