Just one simple piece of advice: Instead of using 4 spaces for indentation in code snippets for blogs, I think it's better to use 2 spaces as it reduces the need for horizontal scrolling.
I'm a software developer currently working on multiple projects at Kellton Tech. Mostly doing TypeScript and React on a daily basis, focusing on front-end work. On a side note I also work with Clojure
/**
* You declare the data in type of array
* Then, you can loop through the list when you neeed
*/constACTIONS=['create','read','update','delete']asconstconstUSER_TYPES=['admin','editor','user','anonymous']asconst/**
* Types guard
*/typeAction=typeofACTIONS[number]typeUserType=typeofUSER_TYPES[number]/**
* Your userActions data with types guard
*/constuserActions:Record<UserType,Action[]>={admin:["create","read","update","delete"],editor:["create","read","update"],user:["read","update"],anonymous:["read"]}
I think this is not a matter of condition. It's a matter of good practice. Example 1 is easy to understand for beginners, but the other one is good to maintain and easy to extend.
A frontend (React) developer on a mission to build beautiful, user-friendly websites. Passionate about learning and growing in this exciting field...…..
I am a proficient Front-end web developer, with over 9 years of experience, and have knowledge of various areas of developing, which includes Front-end, Back-end, Codeigniter,Wordpress, Shopify etc
Just one simple piece of advice: Instead of using 4 spaces for indentation in code snippets for blogs, I think it's better to use 2 spaces as it reduces the need for horizontal scrolling.
Great read. 👌
thanks for this advice 🤍
How about using the tab character? That what it is meant for and every one can set the space to what ever fits best for one.
github.com/gvergnaud/ts-pattern
this is also a good alternative
As always, all gold is in comments :)
will try it thanks 💕
beautiful stuff! rust inspired, perhaps?
Nice read!! a little improvement for the action array.
create a type of actions
then
Voila!
no one should add something weird within 😏
...
that's a great one thanks
My approaching as following
good one too ⭐
didn't expect that anyone would see this post

I think this is not a matter of condition. It's a matter of good practice. Example 1 is easy to understand for beginners, but the other one is good to maintain and easy to extend.
it's a better way to write conditions as you said easy to maintain , extend and debug
Little things like these make you a pro developer. All the best to everyone and thanks to the author for sharing a good and short article.
awesome comment award 🌃⭐
Valuable, Thanks for sharing
Inspiring 👍
This is great!
You get to simplify things further by creating objects with properties that point to specific values instead of checking nonstop for multiple values.
that's exactly it
this is awesome
you are awesome
Thank you 🙏
You're welcome 💕
There is nothing wrong with conditions, you just reshaped the data you are working with
exactly, there is nothing wrong with conditions anyways , it's just a better approach
Amazing tip!
thanks <3
Thank you for posting, I am aspiring to be able to write and understand fluently! Reading these articles from inside perspectives helps tremendously!
glad to hear that 🤍
Really Great Approach, Surely i am going to use in my Project, Awsome Thanks!
that's awesome, have a good one
One more small advice. Just use ENUM for those roles across the project.
imperative vs declarative
Well executed!
thanks 🤍
You are doing great
thanks 💕
Nice one!!!
thanks :)
no thank you. Over-abstractions are harder to maintain when the app grows.
Over-abstractions ?
so when your app grows abstractions is harder to maintain.
Ok
Exactly.
very understandable.
thanks 🤍🔥
Nice code
thanks 🤍
Well explained!
thanks 🤍
Brilliant <3
thanks 🤍
thanks 👌
you are welcome 😌🤍
great
thanks ♥️
Nice. Thank you for this
thanks 🤍😌
Nice explanation.
thanks 🤍
Greate!!!!!
thanks 😌
I like this.
thanks 🤍
Nice
thanks 🤍
Perfect explanation!!!
simple way to do clean code :)
happy to hear that 💕