<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Angela Pat.</title>
    <description>The latest articles on DEV Community by Angela Pat. (@angelapy).</description>
    <link>https://dev.to/angelapy</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F2741103%2F7d407d2d-c5a9-43ee-acfa-19b3817fb256.jpeg</url>
      <title>DEV Community: Angela Pat.</title>
      <link>https://dev.to/angelapy</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/angelapy"/>
    <language>en</language>
    <item>
      <title>Frontend Code organization, regardless of the stack in times of AI 🤖</title>
      <dc:creator>Angela Pat.</dc:creator>
      <pubDate>Tue, 03 Feb 2026 20:28:58 +0000</pubDate>
      <link>https://dev.to/angelapy/frontend-code-organization-regardless-of-the-stack-in-times-of-ai-4c0i</link>
      <guid>https://dev.to/angelapy/frontend-code-organization-regardless-of-the-stack-in-times-of-ai-4c0i</guid>
      <description>&lt;p&gt;Let's talk about Frontend architecture. We all know that Frontend has become complex with the days and why is it so? &lt;br&gt;
Front-end is where all user requirements, user enhancements, use of the Business domain, handling of errors, optimizations, and much more all come together. Our frontend architecture is responsible for the cohesion of the new and old codebase.&lt;/p&gt;
&lt;h3&gt;
  
  
  In the time of AI agents 🤖
&lt;/h3&gt;

&lt;p&gt;Even now, with the rise of AI agent coding tools, &lt;strong&gt;clean and well organized code remains critical&lt;/strong&gt;. &lt;br&gt;
Without clear instructions, AI can easily overcomplicate solutions. AI agents understand domain logic through code structure. The clearer and more consistent patterns you have, the less context the Agent holds, because the agent will follow a predictable organization.&lt;/p&gt;

&lt;p&gt;For that reason, my rule of thumb is simple: &lt;strong&gt;Follow a feature approach&lt;/strong&gt; to code organization&lt;/p&gt;
&lt;h3&gt;
  
  
  What is a feature approach?
&lt;/h3&gt;

&lt;p&gt;Also called a modular approach is the practice of breaking down a solution or user requirements into smaller units, where each unit has a single responsibility.&lt;/p&gt;

&lt;p&gt;Following this approach helps maintain a solution over the long term and makes it easier to add new features, whether they are simple or complex.&lt;/p&gt;
&lt;h3&gt;
  
  
  With so many stacks out there, why not use the basic organization offered by a library or framework?
&lt;/h3&gt;

&lt;p&gt;Of course you can! A framework or library often provides a playground or a basic project structure to get you started. However, as tasks grow bigger and features begin to interact with one another, it becomes our responsibility to break down big user requirements or concepts into self-contained units.&lt;/p&gt;
&lt;h3&gt;
  
  
  A use case:
&lt;/h3&gt;

&lt;p&gt;Let's say your Admin panel website, needs a new feature an &lt;strong&gt;Employees overview&lt;/strong&gt; page with the following use cases:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Page: Employees Overview***
 - Filter (search, role, age range)
 - List employees
 - Open modal for Editing a new employee 
 - Open a modal for adding a new employee
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now, we can design the architecture by breaking the solution into smaller building blocks.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;For example:&lt;/strong&gt; &lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fyks2ewu29hs89u5rry5m.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fyks2ewu29hs89u5rry5m.png" alt="Rough idea structured in blocks" width="800" height="1264"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;With our rough idea in place, we can start organizing our code using a feature approach. We take a big feature and split it into smaller and independent blocks called features or modules.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;project 
└─── common/            
│       └─── components/
│               └──── Modal
│       └─── hooks/ 
│               └─── useUserLanguage.ts  
│       └─── models/ 
│               └─── user.ts 
└─── core/
│       └─── authentication/
│       └─── i18n/
│       └─── translations/
│       └─── router/
│       └─── api/
│       └─── store/
└───features/
│   └───employees-overview/
|       │─── EmployeesOverview.tsx (Main component)
│       └─── components/
│             └────── employee-filter/
│             └────── employee-list/
│             └────── employee-add/
│             └────── employee-edit/
│                        └────── hooks/
│                                 └───── useFetchUser.ts
│                                 └───── useUpdateUser.ts
│                        └────── components/
│                        └────── helpers/ 
│                        └────── models/  
│                        └────── EmployeeEdit.tsx
└───lib/
│   └───utils

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Let me explain you shortly about some of the important folders and what functionality they cover&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;common&lt;/strong&gt; &lt;em&gt;Also called &lt;strong&gt;shared&lt;/strong&gt;&lt;/em&gt;: Contains code that can be reused across features. You can organize them by &lt;strong&gt;components&lt;/strong&gt;, &lt;strong&gt;hooks&lt;/strong&gt;, &lt;strong&gt;composables&lt;/strong&gt;, &lt;strong&gt;helpers&lt;/strong&gt;, etc.

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;helpers&lt;/strong&gt; &lt;em&gt;Also called &lt;strong&gt;functions&lt;/strong&gt;&lt;/em&gt;: Pure functions that performance specific tasks.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;models&lt;/strong&gt;: Represent your entities. It's recommended that your entities match the backend for consistency and a single source of truth, with slight differences when needed, for example, dates (the backend uses UTC, while the frontend uses a Date object).&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;li&gt;

&lt;strong&gt;features&lt;/strong&gt;: Feature-based code aligned with your business goals.&lt;/li&gt;

&lt;li&gt;&lt;p&gt;&lt;strong&gt;core&lt;/strong&gt; (optional): Contains the foundational code of your app. This folder is optional because you can either keep these files in a dedicated core folder, making it easy to find anything your app relies on, or place them directly in your main structure.&lt;/p&gt;&lt;/li&gt;

&lt;li&gt;&lt;p&gt;&lt;strong&gt;lib&lt;/strong&gt; &lt;em&gt;Also called &lt;strong&gt;utility&lt;/strong&gt;&lt;/em&gt; functions: Generic technical functions that are &lt;strong&gt;not related to domain or business logic&lt;/strong&gt; and can be used across your code.&lt;/p&gt;&lt;/li&gt;

&lt;/ul&gt;

&lt;h2&gt;
  
  
  Conclusion 💞
&lt;/h2&gt;

&lt;p&gt;Start thinking in terms of features, responsibilities, and blocks and let your team and AI agents maintain the code more easily 💪&lt;/p&gt;

</description>
      <category>ai</category>
      <category>architecture</category>
      <category>codequality</category>
      <category>frontend</category>
    </item>
    <item>
      <title>Object literals with satisfies operator for UI field mapping</title>
      <dc:creator>Angela Pat.</dc:creator>
      <pubDate>Tue, 29 Apr 2025 17:56:11 +0000</pubDate>
      <link>https://dev.to/angelapy/object-literals-with-satisfies-operator-for-ui-field-mapping-2ggp</link>
      <guid>https://dev.to/angelapy/object-literals-with-satisfies-operator-for-ui-field-mapping-2ggp</guid>
      <description>&lt;p&gt;Our Frontend is responsible for converting fields into labels that make more sense to users.&lt;/p&gt;

&lt;p&gt;So far I have seen the use of &lt;code&gt;Enums&lt;/code&gt; to solve that purpose but we can also use &lt;code&gt;Objects&lt;/code&gt; literals  with &lt;code&gt;satisfies&lt;/code&gt; and I believe its more developer friendly, flexible and when compiled, it resembles JS.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Object literals:&lt;/strong&gt; Meant to be used for key-value pairs.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Object literals with satisfies:&lt;/strong&gt; Preserves the exact literal types.&lt;/p&gt;

&lt;h3&gt;
  
  
  A use case:
&lt;/h3&gt;

&lt;p&gt;Let’s say we have an Artist songs page  that can be sorted by either title, album name, duration , and # of plays. Our sorting mechanism, in this case a REST API, allows sorting by any of the fields. &lt;/p&gt;

&lt;p&gt;First, I would create a declarative sort dropdown component where the keys match the API fields and the values offer user-friendly labels&lt;/p&gt;

&lt;h4&gt;
  
  
  Solution with Object literal
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;artistSongSortOptions&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="na"&gt;title&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Title&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="na"&gt;albumName&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Album name&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="na"&gt;duration&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Duration&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="na"&gt;numberOfPlays&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Number of Plays&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;as&lt;/span&gt; &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;satisfies&lt;/span&gt; &lt;span class="nb"&gt;Record&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="kr"&gt;string&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="kr"&gt;string&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
&lt;span class="c1"&gt;// We make object read-only by using as const&lt;/span&gt;

&lt;span class="c1"&gt;// Create type from artistSongSortOptions keys&lt;/span&gt;
&lt;span class="kd"&gt;type&lt;/span&gt; &lt;span class="nx"&gt;ArtistSongSortBy&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kr"&gt;keyof&lt;/span&gt; &lt;span class="k"&gt;typeof&lt;/span&gt; &lt;span class="nx"&gt;artistSongSortOptions&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;🕵️‍♀️ Hover over that new created type &lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fnmc5o8z08rlr43rc7m1l.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fnmc5o8z08rlr43rc7m1l.png" alt="title, albumName, duration, numberOfPlays" width="800" height="78"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Nice. Object literals are just brilliant ✨&lt;/p&gt;

&lt;p&gt;With this approach you can easily complete the following:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Display a list of available options, coming from &lt;code&gt;Object.keys(artistSongSortOptions)&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;When an option is selected by the user, you can show the user-friendly text by accessing &lt;code&gt;artistSongSortOptions[selectedOption]&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;Fetch API with sortBy of a type &lt;code&gt;ArtistSongSortBy&lt;/code&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  A later use case:
&lt;/h3&gt;

&lt;p&gt;Time passes, and you need to display a new page for multiple artists; an API allows sorting only by one of the valid fields: title, albumName, duration, numberOfPlays, and a new field artistName (it's a list of artists, we would like to sort by artist name as well 😉)&lt;/p&gt;

&lt;p&gt;I would simply use again object literals&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;multiArtistSongSortOptions&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="p"&gt;...&lt;/span&gt;&lt;span class="nx"&gt;artistSongSortOptions&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="na"&gt;artistName&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Artist name&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;as&lt;/span&gt; &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;satisfies&lt;/span&gt; &lt;span class="nb"&gt;Record&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="kr"&gt;string&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="kr"&gt;string&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
&lt;span class="c1"&gt;// We make object read-only by using as const&lt;/span&gt;
&lt;span class="c1"&gt;// Create type from artistSongSortOptions keys&lt;/span&gt;
&lt;span class="kd"&gt;type&lt;/span&gt; &lt;span class="nx"&gt;MultiArtistSongSortBy&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kr"&gt;keyof&lt;/span&gt; &lt;span class="k"&gt;typeof&lt;/span&gt; &lt;span class="nx"&gt;multiArtistSongSortOptions&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;🕵️‍♀️ Hover over that new created type&lt;br&gt;
&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fufqwg2d4k45midqp900k.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fufqwg2d4k45midqp900k.png" alt="title, albumName, duration, numberOfPlays and, artist name" width="800" height="96"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Advantages of developing this way
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Single source of truth: Automatic type updates&lt;/li&gt;
&lt;li&gt;Type safety&lt;/li&gt;
&lt;li&gt;Simple HTML generation&lt;/li&gt;
&lt;li&gt;Consistency with API&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Another way is to use Enums, however I consider the use of object literal more intuitive. If you still prefer Enums and want to use them for field mappings, I would recommend using ESLint, &lt;a href="https://dev.to/angelapy/eslint-rules-for-dealing-with-enums-peculiarities-3p4h"&gt;check out this post&lt;/a&gt;.&lt;/p&gt;

</description>
      <category>typescript</category>
      <category>eslint</category>
    </item>
    <item>
      <title>Eslint rules for dealing with Enums peculiarities</title>
      <dc:creator>Angela Pat.</dc:creator>
      <pubDate>Tue, 29 Apr 2025 17:53:36 +0000</pubDate>
      <link>https://dev.to/angelapy/eslint-rules-for-dealing-with-enums-peculiarities-3p4h</link>
      <guid>https://dev.to/angelapy/eslint-rules-for-dealing-with-enums-peculiarities-3p4h</guid>
      <description>&lt;p&gt;As of now &lt;code&gt;Enum&lt;/code&gt; have their peculiarities in Typescript; they can behave hmm... How should I put it? Inconsistenly. If you still love Enums then, let me suggest some EsLint rules for writing better Enum&lt;/p&gt;

&lt;h2&gt;
  
  
  Table of Contents
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Enums peculiarities&lt;/li&gt;
&lt;li&gt;Helpful ESLint Rules for Enums!&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Prerequisites
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;EsLint: New to ESLint? It helps you write better JavaScript and TypeScript. &lt;a href="https://typescript-eslint.io/" rel="noopener noreferrer"&gt;https://typescript-eslint.io/&lt;/a&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Enums peculiarities &lt;a&gt;&lt;/a&gt;
&lt;/h3&gt;

&lt;p&gt;I am going to walk you through a few peculiarities I’ve come across while building components using declarative rendering.&lt;/p&gt;

&lt;p&gt;Let me show you with examples&lt;/p&gt;

&lt;h4&gt;
  
  
  Enums with string or number values
&lt;/h4&gt;

&lt;p&gt;Enums behave different when its created with string values versus numbers.&lt;/p&gt;

&lt;h5&gt;
  
  
  With string values
&lt;/h5&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt; &lt;span class="kr"&gt;enum&lt;/span&gt; &lt;span class="nx"&gt;TransferStatus&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nx"&gt;Pending&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;pending&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="nx"&gt;Completed&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;completed&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="nx"&gt;Failed&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;failed&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;Object&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;keys&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;TransferStatus&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt; 
&lt;span class="c1"&gt;// Output : ["Pending", "Completed", "Failed"] &lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h5&gt;
  
  
  With number values
&lt;/h5&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt; &lt;span class="kr"&gt;enum&lt;/span&gt; &lt;span class="nx"&gt;TransferStatus&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nx"&gt;Pending&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="nx"&gt;Completed&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="nx"&gt;Failed&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;Object&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;keys&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;TransferStatus&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt; 
&lt;span class="c1"&gt;// Output : ["0", "1", "2", "Pending", "Completed", "Failed"] &lt;/span&gt;
&lt;span class="c1"&gt;// 🤯 Wow, I got all keys and all values&lt;/span&gt;

&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;Object&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;values&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;TransferStatus&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt; 
&lt;span class="c1"&gt;// Output: ["Pending", "Completed", "Failed", 0, 1, 2] &lt;/span&gt;
&lt;span class="c1"&gt;// 🤡 All values and keys&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  Enums declared explicitly versus implicitly
&lt;/h4&gt;

&lt;p&gt;Enums dont behave the same way when they are declared explicitly versus implicitly. With numbers, values may loose order when refactoring&lt;/p&gt;

&lt;h5&gt;
  
  
  With explicit values
&lt;/h5&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt; &lt;span class="kr"&gt;enum&lt;/span&gt; &lt;span class="nx"&gt;GameDifficulty&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nx"&gt;Easy&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="nx"&gt;Normal&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="nx"&gt;Hard&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="c1"&gt;// If ordered alphabetically&lt;/span&gt;
 &lt;span class="kr"&gt;enum&lt;/span&gt; &lt;span class="nx"&gt;GameDifficulty&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nx"&gt;Easy&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="nx"&gt;Hard&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="nx"&gt;Normal&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="c1"&gt;// All good here with order&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h5&gt;
  
  
  With implicit values
&lt;/h5&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="kr"&gt;enum&lt;/span&gt; &lt;span class="nx"&gt;GameDifficulty&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nx"&gt;Easy&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="nx"&gt;Normal&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="nx"&gt;Hard&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="c1"&gt;// If ordered alphabetically&lt;/span&gt;
 &lt;span class="kr"&gt;enum&lt;/span&gt; &lt;span class="nx"&gt;GameDifficulty&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nx"&gt;Easy&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="nx"&gt;Hard&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="nx"&gt;Normal&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="c1"&gt;// value of Hard changed from 2 to 1 &lt;/span&gt;
&lt;span class="c1"&gt;// 🤯 You would have to apply changes everywhere in your code&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Helpful ESLint Rules for Enums!&lt;a&gt;&lt;/a&gt;
&lt;/h3&gt;

&lt;p&gt;If you still love Enums, then I'd suggest using some EsLint rules to enforce consistency and make code more predictable for you and your team members&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Initialize Enum values explicitly for clarity and consistency&lt;/strong&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;'@typescript-eslint/prefer-enum-initializers': 'error'
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Ensure all enum values are unique.&lt;/strong&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;'@typescript-eslint/no-duplicate-enum-values': 'error'
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Use enums with string values only&lt;/strong&gt;
This is the one I like. Consitency all the way! 💞
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;@typescript-eslint/no-magic-numbers': [
      'error',
      {
        'ignoreEnums': false
      }
    ]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Summary
&lt;/h2&gt;

&lt;p&gt;In this post, I address common inconcistencies with Enum when building dynamic declarative components. I also show with some examples that you met when building components dinamycally.&lt;br&gt;
It also shares some EsLint rules to safeguard you against the peculiarities of Enum.&lt;/p&gt;

</description>
      <category>typescript</category>
      <category>eslint</category>
    </item>
  </channel>
</rss>
