<?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: DaniAcu</title>
    <description>The latest articles on DEV Community by DaniAcu (@daniacu).</description>
    <link>https://dev.to/daniacu</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%2F270610%2F376b97c1-16ce-482e-9d2c-830bc7bfe04a.jpeg</url>
      <title>DEV Community: DaniAcu</title>
      <link>https://dev.to/daniacu</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/daniacu"/>
    <language>en</language>
    <item>
      <title>Svelte’s Growing Pains: Runes, Stores, and the Quest for Standards</title>
      <dc:creator>DaniAcu</dc:creator>
      <pubDate>Tue, 16 Sep 2025 20:15:30 +0000</pubDate>
      <link>https://dev.to/daniacu/sveltes-growing-pains-runes-stores-and-the-quest-for-standards-3j98</link>
      <guid>https://dev.to/daniacu/sveltes-growing-pains-runes-stores-and-the-quest-for-standards-3j98</guid>
      <description>&lt;p&gt;I’ve had this thought in my mind for a while. I don’t want to sound pretentious or anything, but I feel like the Svelte development experience was ruined for me when runes were introduced.&lt;br&gt;
I know that stores are still around, and I can use them without issue. However, more and more, the ecosystem seems to be moving away from them.&lt;/p&gt;

&lt;h1&gt;
  
  
  Why I loved stores?
&lt;/h1&gt;

&lt;p&gt;There are great articles about observables and stores in Svelte. Here’s why I think they’re so valuable:&lt;br&gt;
Stores are an excellent way to structure a site and ensure that everything works consistently.&lt;br&gt;
I worked for more than a year on a very large Svelte project. The main problem I saw was the misuse of stores. Why? Because the mental shift wasn’t happening — developers were still thinking in terms of values, not observables.&lt;br&gt;
But we’re building a UI, and when we work with stores, we need to think of everything as an observable — from user actions to API calls.&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%2Fstdlzjes7q3i0iqp237y.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%2Fstdlzjes7q3i0iqp237y.png" alt=" " width="512" height="246"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;It’s actually quite easy once you get used to it: identify where you need the value, and otherwise avoid touching it. Using stores inside components can feel tricky at first, but once you apply the pattern consistently, it becomes very clear.&lt;br&gt;
It’s similar to using RxJS in NestJS — in the end, you can just return an observable in the controller, so the whole flow can stay observable.&lt;br&gt;
Of course, observables can sometimes be painful to manage. But even in those cases, we can isolate the complexity with a specific solution, while keeping the standard approach for the rest of the system. This makes the code easier to deal with in the future.&lt;br&gt;
One of my key rules for observables is: never manually subscribe unless you really know what you’re doing and you’re sure you’ll clean it up. And even then, it’s worth asking if there’s another way to avoid subscribing directly.&lt;br&gt;
I also started using stores as component state. I created a kind of controller that exposes a store and is only managed in the view. This made things feel consistent — both inside components and globally we ended up using the same tool.&lt;br&gt;
And one of the biggest wins was that in Svelte, RxJS worked without an extra library. Observables were first-class citizens thanks to stores. When you’re already thinking in terms of observables, RxJS is fantastic because it gives you everything you need.&lt;/p&gt;

&lt;h1&gt;
  
  
  Runes, the problem of 0 standard
&lt;/h1&gt;

&lt;p&gt;When runes were introduced, every standard in Svelte was disrupted. To be fair, this isn’t exactly a Svelte problem. It’s the natural result of needing backward compatibility during such a big shift.&lt;br&gt;
We’ve seen something similar with Angular, where signals and observables coexist. The difference is that Angular isn’t trying to replace one with the other, while Svelte is positioning runes as the new standard.&lt;br&gt;
There’s nothing inherently wrong with that. But it creates challenges:&lt;br&gt;
Libraries, community practices, and mental models all need to shift.&lt;br&gt;
Even if no library has to be rewritten, developers outside the Svelte community who want their libraries to work with the latest version will likely target runes.&lt;br&gt;
Companies often push to stay on the latest versions. Sometimes because of contracts, security policies, or just a manager googling and deciding based on what they find first.&lt;br&gt;
All of this makes it hard to maintain standardized code in an ecosystem that itself doesn’t feel standardized right now.&lt;br&gt;
At some point, everyone will want to upgrade to the latest Svelte version, from runes to attachments, to new slot patterns. But that will require codebase changes, even for open source projects.&lt;br&gt;
I loved observables in Svelte, and I still want to use the framework because it feels natural and simple. But moving into this new era will take time, and until then we’ll be surfing waves of “no standard” in our codebases.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;I know the Svelte team is doing a great job navigating these changes and trying to keep a clear direction for the framework.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h1&gt;
  
  
  What’s next
&lt;/h1&gt;

&lt;p&gt;I want to keep coding in Svelte, so I’ll try to help the community by creating two libraries that can bring back some standardization to projects especially around observables and services.&lt;/p&gt;

&lt;p&gt;Here are the projects I’m working on:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://dev.to/daniacu/using-apollo-in-svelte-5-7ke"&gt;Apollo Graphql - Finally the right abstraction for Svelte&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;RxJS for Svelte 5 (In progress)&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>svelte</category>
      <category>programming</category>
      <category>graphql</category>
      <category>rxjs</category>
    </item>
    <item>
      <title>Using Apollo in Svelte 5</title>
      <dc:creator>DaniAcu</dc:creator>
      <pubDate>Tue, 16 Sep 2025 20:13:42 +0000</pubDate>
      <link>https://dev.to/daniacu/using-apollo-in-svelte-5-7ke</link>
      <guid>https://dev.to/daniacu/using-apollo-in-svelte-5-7ke</guid>
      <description>&lt;blockquote&gt;
&lt;p&gt;Previous post &lt;a href="https://dev.to/daniacu/sveltes-growing-pains-runes-stores-and-the-quest-for-standards-3j98"&gt;Svelte’s Growing Pains: Runes, Stores, and the Quest for Standards&lt;/a&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;I worked as an engineeer manager in a large e-commerce company in Saudi Arabia. Our frontend architecture was built on &lt;strong&gt;Svelte microfrontends&lt;/strong&gt;, with separate apps handling &lt;strong&gt;user management, checkout, marketing, and search exploration&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;Our backend was fully powered by &lt;strong&gt;GraphQL&lt;/strong&gt;, and in the beginning, we adopted &lt;a href="https://houdinigraphql.com/" rel="noopener noreferrer"&gt;Houdini&lt;/a&gt; as our GraphQL client. Houdini is a great library, but in practice we found that the generated code often felt &lt;strong&gt;unclear and rigid&lt;/strong&gt;, especially for &lt;strong&gt;component-driven queries&lt;/strong&gt; instead of &lt;strong&gt;page-driven queries&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;This became most noticeable when building &lt;strong&gt;smart components&lt;/strong&gt;—UI elements that need to handle their own API calls, such as:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;A &lt;strong&gt;header&lt;/strong&gt; showing user login state&lt;/li&gt;
&lt;li&gt;A &lt;strong&gt;shopping cart widget&lt;/strong&gt; with live updates&lt;/li&gt;
&lt;li&gt;Shared &lt;strong&gt;navigation or marketing components&lt;/strong&gt; that are reused across apps but still need to be intelligent and data-driven&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;In these cases, we needed something &lt;strong&gt;flexible&lt;/strong&gt; and &lt;strong&gt;reactive&lt;/strong&gt;, with a clear mental model and strong tooling support.&lt;/p&gt;

&lt;h2&gt;
  
  
  Why Apollo?
&lt;/h2&gt;

&lt;p&gt;Given the scale of our system, we leaned towards &lt;strong&gt;Apollo Client&lt;/strong&gt;, because it provides:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Robust cache normalization&lt;/strong&gt; out of the box&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Excellent developer tools&lt;/strong&gt; for debugging and inspecting queries&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Rich ecosystem support&lt;/strong&gt; (links, error handling, pagination strategies, etc.)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Since other parts of our company were already using Apollo in React and Angular projects, aligning on Apollo also reduced the cognitive overhead for new team members.&lt;/p&gt;

&lt;h2&gt;
  
  
  The Challenge in Svelte 5
&lt;/h2&gt;

&lt;p&gt;At the time of migrating from &lt;strong&gt;Svelte 4 → Svelte 5&lt;/strong&gt;, the only official option for Apollo in Svelte was &lt;a href="https://github.com/timhall/svelte-apollo" rel="noopener noreferrer"&gt;&lt;code&gt;svelte-apollo&lt;/code&gt;&lt;/a&gt;. Unfortunately, it had not been updated in several years and was missing modern Svelte 5 features like &lt;strong&gt;runes&lt;/strong&gt; and &lt;strong&gt;fine-grained reactivity&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;What I wanted was:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;The full power of Apollo Client&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;First-class Svelte 5 integration&lt;/strong&gt; (no extra boilerplate, reactive by default)&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;An experience as smooth as React&lt;/strong&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  The Solution
&lt;/h2&gt;

&lt;p&gt;That’s why I built &lt;strong&gt;this library&lt;/strong&gt;—to bring Apollo’s ecosystem and developer experience into the Svelte 5 world.&lt;/p&gt;

&lt;p&gt;It provides, &lt;strong&gt;reactive queries and mutations&lt;/strong&gt; that fit naturally with Svelte 5 runes&lt;/p&gt;

&lt;p&gt;With this library, you can enjoy &lt;strong&gt;Apollo’s power + Svelte’s simplicity&lt;/strong&gt; without compromises.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://apollo-runes-docs.vercel.app/" rel="noopener noreferrer"&gt;Apollo Runes&lt;/a&gt;&lt;br&gt;
&lt;strong&gt;If you found this useful, consider giving it a ⭐ on GitHub. Thanks!&lt;/strong&gt;&lt;/p&gt;

</description>
      <category>svelte</category>
      <category>apollo</category>
      <category>graphql</category>
      <category>javascript</category>
    </item>
    <item>
      <title>Answer Dev Questions #1: Demystifying Special Characters in Paths</title>
      <dc:creator>DaniAcu</dc:creator>
      <pubDate>Fri, 26 May 2023 01:23:21 +0000</pubDate>
      <link>https://dev.to/daniacu/answer-dev-questions-1-demystifying-special-characters-in-paths-3hl9</link>
      <guid>https://dev.to/daniacu/answer-dev-questions-1-demystifying-special-characters-in-paths-3hl9</guid>
      <description>&lt;p&gt;Recently, while engaging in a online discussion, a question caught my attention. &lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Sometimes i see symbols like “@“ or “*&lt;em&gt;” or “&lt;/em&gt;” or “^” or “~”&lt;br&gt;
And I don't know what are they used in ..?!&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;I wait some time, but I saw that anyone answer the question, I just saw one intention to doit that was a link of a blog post that not track the entire question. So I take the time to answer it, and after doing it I just ask to myself: Why do not create post of this answer?&lt;/p&gt;

&lt;p&gt;So here I am, maybe for expert it sounds easy-peasy or like a piece of cake but for the most beginers that try to find some guide in the masive world of things it could be helpful.&lt;/p&gt;

&lt;p&gt;All this symbols in the question are  for different things.&lt;/p&gt;

&lt;h2&gt;
  
  
  @
&lt;/h2&gt;

&lt;p&gt;&lt;em&gt;Let start with the &lt;strong&gt;at symbol (@)&lt;/strong&gt;.&lt;/em&gt; As the question was asked about a js file, so I could say that in JS projects is used to have a convenient way to access to root folder of your app. &lt;br&gt;
&lt;strong&gt;Instead of doing &lt;code&gt;../../../../../../../../../&lt;/code&gt;&lt;/strong&gt;, accesing from the root could be shorted but the most important benefit is that &lt;strong&gt;alias is the same for every file&lt;/strong&gt;. So &lt;strong&gt;moving file dont need update imports&lt;/strong&gt;. &lt;br&gt;
For more information check the &lt;a href="https://github.com/rollup/plugins/tree/master/packages/alias#readme"&gt;rollup alias plugin&lt;/a&gt; &lt;/p&gt;

&lt;h2&gt;
  
  
  *, **, ^
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;The asterisks (* or **), carret(^),&lt;/strong&gt; is more a OS thing or to be specific is part of glob (&lt;a href="https://en.wikipedia.org/wiki/Glob_(programming)"&gt;https://en.wikipedia.org/wiki/Glob_(programming)&lt;/a&gt;). &lt;br&gt;
In general it means the following:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;* (any file)&lt;/li&gt;
&lt;li&gt;** (any folder)&lt;/li&gt;
&lt;li&gt;^ (exclude this, but I think that you need some extension of glob or something like that. check this &lt;a href="https://unix.stackexchange.com/questions/355967/what-does-the-caret-do-in-zsh"&gt;discussion about it&lt;/a&gt;)&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  ~
&lt;/h2&gt;

&lt;p&gt;The tilde symbol (~) is for user directory. In linux you could go to your user directory using "cd ~" any time. Some any path written with than means that is searching the path starting form user directory, it an alias already provided by the OS. &lt;a href="https://en.wikipedia.org/wiki/Tilde#Directories_and_URLs"&gt;Check this link&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;I hope this explanation was helpful to you, because I really enjoy wrinting this answer.&lt;/p&gt;

&lt;p&gt;See you in the next one.&lt;/p&gt;

&lt;p&gt;Here my links.&lt;br&gt;
&lt;a href="https://twitter.com/Daniacu98"&gt;Twitter&lt;/a&gt;&lt;br&gt;
&lt;a href="https://github.com/DaniAcu"&gt;Github&lt;/a&gt;&lt;/p&gt;

</description>
      <category>linux</category>
      <category>beginners</category>
      <category>path</category>
      <category>javascript</category>
    </item>
    <item>
      <title>Observations about Svelte</title>
      <dc:creator>DaniAcu</dc:creator>
      <pubDate>Wed, 24 Aug 2022 01:50:00 +0000</pubDate>
      <link>https://dev.to/daniacu/svelte-4do8</link>
      <guid>https://dev.to/daniacu/svelte-4do8</guid>
      <description>&lt;p&gt;In the last couple of months, I worked on an Indoor Map solution where we used Svelte to develop the user interface. It was a surprising decision because I had never worked with this tool, so I dedicated some time to learning about it and starting to set up the environment to work above it.&lt;/p&gt;

&lt;h2&gt;
  
  
  Intro
&lt;/h2&gt;

&lt;p&gt;For people how are not familiarized with Svelte, this is a new kind of framework in the frontend world. But it's more a language than a framework. There is a lot of confusion on the Internet about what Svelte really is and whatnot. Some people mention that Svelte is a compiler that compiles your code into plain Javascript, which is not entirely true. Because like other frameworks Svelte is adding an internal package to do that everything works correctly.&lt;/p&gt;

&lt;p&gt;Svelte is an extension of the Javascript language which helps you to create reactive sites. This means that there is some Svelte code that only works in a Svelte environment, not as a normal Javascript. But all this code is compiled to be able to run in any browser.&lt;/p&gt;

&lt;h2&gt;
  
  
  How svelte works?
&lt;/h2&gt;

&lt;p&gt;One of the main thing that svelte does is syncing the template with the code. Let see an example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;&lt;span class="c"&gt;&amp;lt;!--- Home.svelte ---&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;script&amp;gt;&lt;/span&gt;
   &lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;name&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Dani&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/script&amp;gt;&lt;/span&gt;

&lt;span class="nt"&gt;&amp;lt;h1&amp;gt;&lt;/span&gt;Hello {name}&lt;span class="nt"&gt;&amp;lt;/h1&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;As you could see this svelte file has two sections. First, the script where we declare the variables that we want to use and next to an HTML text where we could use curly brackets to map the variables into the template.&lt;/p&gt;

&lt;p&gt;But how this magic works? Well, one of the things that Svelte doesn't do is use a VDOM algorithm. They don't have a representation of the DOM, they just process the updates directly to the DOM, which in most cases, improves the performance.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;&lt;span class="c"&gt;&amp;lt;!--- Home.svelte ---&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;script&amp;gt;&lt;/span&gt;
    &lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;name&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Dani&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

    &lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nx"&gt;onChange&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;e&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="nx"&gt;name&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;e&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;target&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;value&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/script&amp;gt;&lt;/span&gt;

&lt;span class="nt"&gt;&amp;lt;h1&amp;gt;&lt;/span&gt;Hello {name}&lt;span class="nt"&gt;&amp;lt;/h1&amp;gt;&lt;/span&gt;

&lt;span class="nt"&gt;&amp;lt;input&lt;/span&gt; &lt;span class="na"&gt;type=&lt;/span&gt;&lt;span class="s"&gt;"text"&lt;/span&gt; &lt;span class="na"&gt;on:change=&lt;/span&gt;&lt;span class="s"&gt;{onChange}&lt;/span&gt; &lt;span class="nt"&gt;/&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Let see what Svelte is doing in this simple case:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;When the &lt;code&gt;h1&lt;/code&gt; renders, they detect the &lt;code&gt;name&lt;/code&gt; variable as a dependency, so &lt;code&gt;h1&lt;/code&gt; will subscribe to all updates that the &lt;code&gt;name&lt;/code&gt; will have.&lt;/li&gt;
&lt;li&gt;When &lt;code&gt;onChange&lt;/code&gt; modify the value, the compiler adds an update method below your assignment
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight jsx"&gt;&lt;code&gt;&lt;span class="c1"&gt;// pseudo code&lt;/span&gt;
&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nx"&gt;onChange&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;e&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;name&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;e&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;target&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;value&lt;/span&gt;
    &lt;span class="nx"&gt;$$update&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;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;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This method will get all the subscribers to the variable &lt;code&gt;name&lt;/code&gt; and run the updates.&lt;/p&gt;

&lt;p&gt;Pay attention to the word that I used before, &lt;em&gt;assignment&lt;/em&gt;. This is important especially when you work with complex data types like arrays, objects, or others.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight jsx"&gt;&lt;code&gt;&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nx"&gt;updateComplexValue&lt;/span&gt; &lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;arr&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;push&lt;/span&gt;&lt;span class="p"&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;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The previous code will not trigger any render update, because the compiler doesn't see any assignment. So, it's so simple as adding what the compiler is expected to trigger the render.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight jsx"&gt;&lt;code&gt;&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nx"&gt;updateComplexValue&lt;/span&gt; &lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;arr&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;push&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

    &lt;span class="c1"&gt;// This doesn't do anything. Just tell the compiler that we need a new render&lt;/span&gt;
    &lt;span class="nx"&gt;arr&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;arr&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; 
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;So in terms of logic, this doesn't change anything. But now the compiler identify an assignment and they could add the update method below that.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight jsx"&gt;&lt;code&gt;&lt;span class="c1"&gt;// pseudo code&lt;/span&gt;
&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nx"&gt;updateComplexValue&lt;/span&gt; &lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;arr&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;push&lt;/span&gt;&lt;span class="p"&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;arr&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;arr&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; 
    &lt;span class="nx"&gt;$$update&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;arr&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;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  How does reactivity work?
&lt;/h2&gt;

&lt;p&gt;The reason why I think that svelte is more than a simple framework is for this reason. Svelte add reactive declaration which allows you to create a new type of variable, a computed variable (as Vue called 😉). Variables or blocks will be updated every time based on their dependencies.&lt;/p&gt;

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

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight jsx"&gt;&lt;code&gt;&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;firstName&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Daniel&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;
&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;lastName&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Acuña&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;

&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;name&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;`&lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;firstName&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt; &lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;lastName&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;`&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The &lt;code&gt;name&lt;/code&gt; will always be "Daniel Acuña" because there is no mechanism that said that each time that &lt;code&gt;firstName&lt;/code&gt; or &lt;code&gt;lastName&lt;/code&gt; change we need to regenerate the variable. But but but, Svelte extends the language to do it possible.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight jsx"&gt;&lt;code&gt;&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;firstName&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Daniel&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;
&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;lastName&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Acuña&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;

&lt;span class="nx"&gt;$&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;name&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;`&lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;firstName&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt; &lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;lastName&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;`&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now you will have &lt;code&gt;name&lt;/code&gt; variable, which is reactive and is dependent on &lt;code&gt;firstName&lt;/code&gt; and &lt;code&gt;lastName&lt;/code&gt;, each time when these updates &lt;code&gt;name&lt;/code&gt; will be calculated again.&lt;/p&gt;

&lt;p&gt;Also, you could use it as a block that runs in every update.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight jsx"&gt;&lt;code&gt;&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;firstName&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Daniel&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;
&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;lastName&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Acuña&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;

&lt;span class="nx"&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="nx"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;`&lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;firstName&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt; &lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;lastName&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;`&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  How empower reactivity?
&lt;/h2&gt;

&lt;p&gt;Reactive programming is not just about magic things going on. It's about events, subscriptions, and streams. Svelte create their own stores that allow you to use streams to share info between components.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight jsx"&gt;&lt;code&gt;&lt;span class="c1"&gt;// count.store.js&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;writable&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;svelte/store&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;count&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;writable&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="c1"&gt;// Counter.svelte&lt;/span&gt;
&lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nt"&gt;script&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
import &lt;span class="si"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;count&lt;/span&gt; &lt;span class="si"&gt;}&lt;/span&gt; from './count.store';

let value = 0;

count.subscribe(newValue =&amp;gt; &lt;span class="si"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;value&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;newValue&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="si"&gt;}&lt;/span&gt;)
&lt;span class="p"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nt"&gt;script&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;

&lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nt"&gt;span&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;Count: &lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;value&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="p"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nt"&gt;span&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;

&lt;span class="c1"&gt;// Increment.svelte&lt;/span&gt;
&lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nt"&gt;script&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
import &lt;span class="si"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;count&lt;/span&gt; &lt;span class="si"&gt;}&lt;/span&gt; from './count.store';

function onClick () &lt;span class="si"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;count&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;update&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;n&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;n&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="si"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nt"&gt;script&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;

&lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nt"&gt;button&lt;/span&gt; &lt;span class="na"&gt;on&lt;/span&gt;&lt;span class="err"&gt;:&lt;/span&gt;&lt;span class="na"&gt;click&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;onClick&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
    +
&lt;span class="p"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nt"&gt;button&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;We are just sharing a structure to two different files, and as you could see we are subscribing in a component to be able to read the current value, but we also need to unsubscribe. However, all the subscription management could be annoying if we are using a lot of stores. So svelte, again, create a syntaxis to do it more easily to everyone.Reactive programming is not just about magic things going on. It's about events, subscriptions, and streams. Svelte create their own stores that allow you to use streams to share info between components.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight jsx"&gt;&lt;code&gt;&lt;span class="c1"&gt;// Counter.svelte&lt;/span&gt;
&lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nt"&gt;script&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
import &lt;span class="si"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;count&lt;/span&gt; &lt;span class="si"&gt;}&lt;/span&gt; from './count.store';
&lt;span class="p"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nt"&gt;script&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;

&lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nt"&gt;span&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;Count: &lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;$count&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="p"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nt"&gt;span&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Using the &lt;code&gt;$&lt;/code&gt; symbol, we are let that Svelte managed the subscriptions. So when the component mounts it will be subscribed and when the component unmount it will trigger an unsubscription. We just need to use it in this way to show the value.&lt;/p&gt;

&lt;p&gt;The interface that svelte proposes to the subscription is completely common, so you could change it with any library that uses the same contract. The famous stream library RxJS is one of the cases for example.&lt;/p&gt;

&lt;p&gt;If you want to empower the reactivity into Svelte, Rxjs is a good choice to take. Because you open the door to new possibilities to manage the streams.&lt;/p&gt;

&lt;p&gt;If you are really interested in learning more about how to integrate RxJS with Svelte, I highly recommend this post by Tim Deschryver. &lt;a href="https://timdeschryver.dev/blog/unlocking-reactivity-with-svelte-and-rxjs"&gt;https://timdeschryver.dev/blog/unlocking-reactivity-with-svelte-and-rxjs&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Some consideration
&lt;/h2&gt;

&lt;p&gt;Svelte is a open source framework but the community doesn't dedicate time to develop useful libraries to work abov it.&lt;/p&gt;

&lt;p&gt;For example, if you try to find UI libraries to work with a Desing System you could find some libraries for Material Design with a lot of accesibility issues. Maybe one of the best options is Carbon Desing but all this depend of what do you want kind of app you want to develop. In addition to that, the integration of this libraries needs a extra set some extra configuration in your project to do that everything works.&lt;/p&gt;

&lt;p&gt;Some UI libraries recommendation:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://smeltejs.com/"&gt;Smelte&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://carbon-components-svelte.onrender.com/"&gt;Carbon Desing&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Also, svelte has a tech dep for some useful functions and components that they not provide yet. For example, they provide a way to render components dynamically (&lt;code&gt;&amp;lt;svelte:component /&amp;gt;&lt;/code&gt;) but not a way to use dynamic element (I imagine, something like &lt;code&gt;&amp;lt;svelte:element/&amp;gt;&lt;/code&gt;). You could check the current status of this feature in this issue &lt;a href="https://github.com/sveltejs/svelte/issues/2324"&gt;#2324&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Althought, this is a framework in development with a lot of improvements to do. Currently, Rich Harris the creator of svelte is moving to Vercel, so we should wait for new and cool things comming. &lt;a href="https://vercel.com/blog/vercel-welcomes-rich-harris-creator-of-svelte"&gt;Check the news&lt;/a&gt;&lt;/p&gt;

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

&lt;p&gt;Svelte is so free that you could create whatever kind of code that you could imagine. This comes with pros and cons, but it all depends on your experience working with the reactive site.&lt;/p&gt;

&lt;p&gt;If you are building something small like a micro app, svelte could be a good fit to choose. If you would like to learn about reactive programming maybe is a good place to start learning by doing so stuff.&lt;/p&gt;

&lt;p&gt;Svelte has a really good future and also is putting in discussion a lot of pre-conceptions that other frameworks have. So I feel that it will help in the next generation of front-end technologies.&lt;/p&gt;

</description>
    </item>
    <item>
      <title>Tips and Tricks for Typescript to daily use</title>
      <dc:creator>DaniAcu</dc:creator>
      <pubDate>Wed, 08 Sep 2021 20:03:19 +0000</pubDate>
      <link>https://dev.to/daniacu/tips-and-tricks-for-typescript-to-daily-use-1cca</link>
      <guid>https://dev.to/daniacu/tips-and-tricks-for-typescript-to-daily-use-1cca</guid>
      <description>&lt;p&gt;I often see that JS devs struggle to create good types in Typescript. Some people use the famous &lt;code&gt;any&lt;/code&gt; and other use unspecific types.&lt;/p&gt;

&lt;p&gt;First of all, I'd like to remark that &lt;strong&gt;good typing helps you to think less and reduce to time to check the implementation&lt;/strong&gt;. In Functional Programming, the function definition is so important for the same reason. Your types should be thrust and strictly define which is the structure of your data.&lt;/p&gt;

&lt;p&gt;Today, we'll explore some tips about how to use some utils types and some extra cases that will help you on a daily basis.&lt;/p&gt;

&lt;h2&gt;
  
  
  Pick and Omit
&lt;/h2&gt;

&lt;p&gt;These two utils are part of the utils that comes with Typescript. These are helpful for preventing rewrite interfaces every time that we need something similar. Let's see in action in a real example.&lt;/p&gt;

&lt;p&gt;Imagine that we are creating a store to be used in some components.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight tsx"&gt;&lt;code&gt;&lt;span class="kr"&gt;interface&lt;/span&gt; &lt;span class="nx"&gt;Stores&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;user&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;User&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="nx"&gt;theme&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;Theme&lt;/span&gt;
  &lt;span class="c1"&gt;// ... some others&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If we want to define the props of our component that also comes with some of these stores we don't need to replicate it like that:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight tsx"&gt;&lt;code&gt;&lt;span class="kr"&gt;interface&lt;/span&gt; &lt;span class="nx"&gt;AvatarProps&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;user&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;User&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="nx"&gt;rounded&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;boolean&lt;/span&gt;
  &lt;span class="c1"&gt;// ... some others&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Instead, we could use these utils types to prevent repeat these types, and reduce some mistakes like add another type for the user prop.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight tsx"&gt;&lt;code&gt;&lt;span class="kr"&gt;interface&lt;/span&gt; &lt;span class="nx"&gt;AvatarProps&lt;/span&gt; &lt;span class="kd"&gt;extends&lt;/span&gt; &lt;span class="nb"&gt;Pick&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;Stores&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;user&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="na"&gt;rounded&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;boolean&lt;/span&gt;
  &lt;span class="c1"&gt;// ... some others&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;&lt;code&gt;Pick&lt;/code&gt; util just create a new type only with the keys that match with the second type that we passed&lt;/strong&gt;. Imagine this like a function with 2 parameters, the first one is the whole type and the second one is a union with the names that we need to "pick". Remember a union is a conjunction of 2 or more types, in this case, we use a fixed string to match with each key.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight tsx"&gt;&lt;code&gt;&lt;span class="kr"&gt;interface&lt;/span&gt; &lt;span class="nx"&gt;Foo&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;key1&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kr"&gt;number&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="nx"&gt;key2&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kr"&gt;number&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="nx"&gt;key3&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kr"&gt;number&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="kd"&gt;type&lt;/span&gt; &lt;span class="nx"&gt;FooPicked&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;Pick&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;Foo&lt;/span&gt; &lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;key1&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt; &lt;span class="o"&gt;|&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;key2&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;

&lt;span class="cm"&gt;/*

This will result in a type like that:

interface FooPicked {
  key1: number,
  key2: number
}

*/&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;&lt;code&gt;Omit&lt;/code&gt; util does the same thing but in inverse order. I mean instead of taking every key that matches with the union it'll "omit" every key that matches with the union.&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight tsx"&gt;&lt;code&gt;&lt;span class="kr"&gt;interface&lt;/span&gt; &lt;span class="nx"&gt;Foo&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;key1&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kr"&gt;number&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="nx"&gt;key2&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kr"&gt;number&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="nx"&gt;key3&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kr"&gt;number&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="kd"&gt;type&lt;/span&gt; &lt;span class="nx"&gt;FooOmited&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;Omit&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;Foo&lt;/span&gt; &lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;key1&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt; &lt;span class="o"&gt;|&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;key2&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;

&lt;span class="cm"&gt;/*

This will result in a type like that:

interface FooOmited {
  key3: number
}

*/&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Partial
&lt;/h2&gt;

&lt;p&gt;We were talking about the store so let continue with that. In this case let think about action, mutation, or anything that will do an update. For example, let use the old setState that React uses in classes as an example.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight tsx"&gt;&lt;code&gt;&lt;span class="c1"&gt;// state&lt;/span&gt;
&lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;state&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="na"&gt;foo&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;foo&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="na"&gt;bar&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;bar&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="c1"&gt;// mutation&lt;/span&gt;
&lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;setState&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;
  &lt;span class="na"&gt;foo&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;foo&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;
&lt;span class="p"&gt;})&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The method setState needs to receive just a part of the whole state, but we can't use Pick or Omit, because we don't know which will be the key that will be omitted. So, for these cases, we need to send a "partial interface" that will be merged with the whole interface.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight tsx"&gt;&lt;code&gt;&lt;span class="c1"&gt;// state&lt;/span&gt;
&lt;span class="kr"&gt;interface&lt;/span&gt; &lt;span class="nx"&gt;State&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;foo&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kr"&gt;string&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="nx"&gt;bar&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kr"&gt;string&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="c1"&gt;// mutation&lt;/span&gt;
&lt;span class="kd"&gt;type&lt;/span&gt; &lt;span class="nx"&gt;SetState&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;value&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;Partial&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;State&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;State&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;But what is doing this &lt;code&gt;Partial&lt;/code&gt; behind the scene, well it's not so complicated. &lt;strong&gt;It's just adding optional to each first-level property.&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight tsx"&gt;&lt;code&gt;&lt;span class="c1"&gt;// state&lt;/span&gt;

&lt;span class="kr"&gt;interface&lt;/span&gt; &lt;span class="nx"&gt;State&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;foo&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kr"&gt;string&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="nx"&gt;bar&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kr"&gt;string&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="kd"&gt;type&lt;/span&gt; &lt;span class="nx"&gt;PartialState&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;Partial&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;State&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="cm"&gt;/*

This will result in a type like that:

interface PatialState {
  foo?: string,
  bar?: string
}

*/&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You could find another case where you need to use it. Just remember that only put optional to first level properties, if you have nested object the child properties will not be impacted by this util.&lt;/p&gt;

&lt;h2&gt;
  
  
  readonly
&lt;/h2&gt;

&lt;p&gt;If you like to work with immutable data maybe you'll love this keyword. &lt;strong&gt;Typescript allows you to determine which properties of your object could modify or not.&lt;/strong&gt; Continue with the stores, if you will use the Flux architecture you don't want to allow that the state to be modified, you just want to recreate the state in each action.&lt;/p&gt;

&lt;p&gt;So for these cases are helpful to put these properties as readonly because it will throw an error if anyone tries to modify it.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight tsx"&gt;&lt;code&gt;&lt;span class="kr"&gt;interface&lt;/span&gt; &lt;span class="nx"&gt;Stores&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;readonly&lt;/span&gt; &lt;span class="nx"&gt;user&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;User&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="k"&gt;readonly&lt;/span&gt; &lt;span class="nx"&gt;theme&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;Theme&lt;/span&gt;
  &lt;span class="c1"&gt;// ... some others&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Also, you could use the Readonly util&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight tsx"&gt;&lt;code&gt;&lt;span class="kd"&gt;type&lt;/span&gt; &lt;span class="nx"&gt;ReadonlyStores&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;Readonly&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;Stores&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;When you try to modify any value, you will see an error message.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight tsx"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;store&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;ReadonlyStores&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="na"&gt;user&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nx"&gt;User&lt;/span&gt;&lt;span class="p"&gt;(),&lt;/span&gt;
  &lt;span class="na"&gt;theme&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nx"&gt;Theme&lt;/span&gt;&lt;span class="p"&gt;(),&lt;/span&gt;
  &lt;span class="c1"&gt;// ... some others&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="nx"&gt;stores&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;user&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nx"&gt;User&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
&lt;span class="c1"&gt;// Error: Cannot assign to 'user' because it is a read-only property.&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;IMPORTANT&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;This check will throw an error in compile-time but not during runtime as &lt;code&gt;const&lt;/code&gt; does.&lt;/strong&gt; It means that if you have a code that typescript is not tracking, it will easily modify your property in runtime. Just prevent skipping typescript rules from your files.&lt;/p&gt;

&lt;h2&gt;
  
  
  Smart use of infer typing
&lt;/h2&gt;

&lt;p&gt;Typescript has a really powerful inference algorithm. This means that sometimes we don't need to be explicit with the type of a variable because it will directly be typed for you.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight tsx"&gt;&lt;code&gt;&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;a&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;a&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt; &lt;span class="c1"&gt;// Typescript infer that it will be a "string"&lt;/span&gt;
&lt;span class="nx"&gt;a&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;3&lt;/span&gt; &lt;span class="c1"&gt;// It'll throw an error&lt;/span&gt;

&lt;span class="c1"&gt;// Just need to specify the type if you are not passing a value to the variable&lt;/span&gt;
&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;a&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kr"&gt;string&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="nx"&gt;a&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;a&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;

&lt;span class="c1"&gt;// In another way it will be typed as any&lt;/span&gt;
&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;a&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="c1"&gt;// typescript typed as any (some config will prevent this automatic any type)&lt;/span&gt;
&lt;span class="nx"&gt;a&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;a&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;
&lt;span class="nx"&gt;a&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;3&lt;/span&gt; &lt;span class="c1"&gt;// it will NOT throw an error&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;We could use this superpower for our benefit. Continue with our store, instead of creating the interface like that...&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight tsx"&gt;&lt;code&gt;&lt;span class="kr"&gt;interface&lt;/span&gt; &lt;span class="nx"&gt;Stores&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;user&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;User&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="nx"&gt;theme&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;Theme&lt;/span&gt;
  &lt;span class="c1"&gt;// ... some others&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;stores&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;Stores&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="na"&gt;user&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nx"&gt;User&lt;/span&gt;&lt;span class="p"&gt;(),&lt;/span&gt;
  &lt;span class="na"&gt;theme&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nx"&gt;Theme&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;... we could give the responsability to typescript to create it automatically.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight tsx"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;stores&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="na"&gt;user&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nx"&gt;User&lt;/span&gt;&lt;span class="p"&gt;(),&lt;/span&gt;
  &lt;span class="na"&gt;theme&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nx"&gt;Theme&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="kd"&gt;type&lt;/span&gt; &lt;span class="nx"&gt;Stores&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;typeof&lt;/span&gt; &lt;span class="nx"&gt;stores&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The common &lt;code&gt;typeof&lt;/code&gt; keyword takes a new power in typescript. It will return the type that typescript infers of the declaration of the variable. &lt;strong&gt;So both codes are doing the same thing.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;I love this feature because in these cases the type is completely dependent on the declaration. If you add a new field you just need to add it in the declaration and it will propagate to type immediately. Instead in the manual interface creation, you need to propagate this by your self which could come with some mistakes.&lt;/p&gt;

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

&lt;p&gt;Typescript is fabulous, but as you could see with the difference between readonly and const, typescript just creates a layer for the developer to make the code more secure for all. But the JS code that is generated will not follow the rules. So it could modify the readonly property or have access to private attributes because it just a layer while you are coding.&lt;/p&gt;

&lt;p&gt;Also if you are using classes to privatize some methods or attributes, it will be just "private" before compilation. If you really want to use a private value you could use a closure factory, also this could reduce just a little bit the bundle size of your compiled code because there now any necesity to compile anything like when you are using a class. &lt;a href="https://github.com/reduxjs/react-redux/pull/1755"&gt;If you are looking for a example of that let check this rewrite that Mark Erikson did in the Subscription of react-redux.&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Remember this when you are working with typescript it will help you understand what is happening behind the scenes.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Thank you for reading this post. I hope this helps you in your daily work.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;If you would like to learn more, I highly recommend the Typescript documentation for utils.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://www.typescriptlang.org/docs/handbook/utility-types.html"&gt;https://www.typescriptlang.org/docs/handbook/utility-types.html&lt;/a&gt;&lt;/p&gt;

</description>
      <category>typescript</category>
      <category>javascript</category>
      <category>utils</category>
    </item>
    <item>
      <title>My Road to Isomorphic Apps</title>
      <dc:creator>DaniAcu</dc:creator>
      <pubDate>Tue, 07 Jan 2020 23:03:50 +0000</pubDate>
      <link>https://dev.to/daniacu/my-history-of-web-app-5996</link>
      <guid>https://dev.to/daniacu/my-history-of-web-app-5996</guid>
      <description>&lt;p&gt;&lt;em&gt;The web app world changed a lot in the last years&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;When I started coding, we were creating the pages in a static way. Maybe you remember that. We created a little app with our HTML, CSS and (if you were little crazy) Javascript. &lt;/p&gt;

&lt;h2&gt;
  
  
  Static Pages
&lt;/h2&gt;

&lt;p&gt;At that moment we only created pages with a simple structure and only reused little things. The scalability of these projects was very heavy. All file work alone, for sample on a simple landing page to one company, we had one HTML by page. At that time, the developers started loving jQuery. Many developers knew jQuery but he didn't know Javascript, that was crazy times.&lt;/p&gt;

&lt;p&gt;For sample, if you went to &lt;strong&gt;/about .html&lt;/strong&gt;, you received an about page. This page has its own style and JavaScript code. Something similar to that.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--VFejW6aj--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://thepracticaldev.s3.amazonaws.com/i/hhyuxg345b23imgxn619.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--VFejW6aj--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://thepracticaldev.s3.amazonaws.com/i/hhyuxg345b23imgxn619.png" alt="static page example" width="800" height="404"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Server Pages (PHP)
&lt;/h2&gt;

&lt;p&gt;In my experience, I used PHP and his frameworks before to use a Javascript framework. To reuse many parts of one page, we have includes functions on our server. This a sample on PHP but it's the same or similar to other languages and templates, like Java using something like JSP.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--TtMhYLyD--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://thepracticaldev.s3.amazonaws.com/i/kmbk150or271t0tfclmh.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--TtMhYLyD--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://thepracticaldev.s3.amazonaws.com/i/kmbk150or271t0tfclmh.png" alt="server page php example" width="620" height="508"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;We came to the &lt;strong&gt;PHP&lt;/strong&gt; &lt;em&gt;frameworks&lt;/em&gt; like &lt;strong&gt;Laravel&lt;/strong&gt;, &lt;strong&gt;Symfony&lt;/strong&gt; and others. This way to reused page takes a superpower. On these frameworks, we could create layouts and extends that to only add the content that we need to use it. &lt;/p&gt;

&lt;h2&gt;
  
  
  Single Page Application (SPA)
&lt;/h2&gt;

&lt;p&gt;With BackboneJS comes the idea to SPA, an HTML creates dynamic pages by JavaScript. But the most relevant framework that all developers remember that it starts with the SPA is AngularJS. &lt;br&gt;
On Angular, you create a simple mapper from route to template, and this template uses a controller with the JavaScript logic.&lt;br&gt;
The concept of SPA is to create a friendly experience to the user with a flow very similar to a desktop application.&lt;br&gt;
This type of apps creates a lot of work on the UI side and creates a boom to JavaScript. So many developers started to learn JavaScript with AngularJS.  And now we have pages created just with javascript.&lt;/p&gt;

&lt;h3&gt;
  
  
  Some issues on SPA
&lt;/h3&gt;

&lt;p&gt;The best thing on this type of app is the experience because you don't need to request the page to the server and you could create an animation between a route to route because it is the same HTML page. But not all is great...&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Not a friendly integration with SEO&lt;/strong&gt;&lt;br&gt;
Friendly SEO is very hard, because when you or a bot try to get the code. You received something like that...&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--buO-syXy--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://thepracticaldev.s3.amazonaws.com/i/n14zydidvyv2cwqos6f5.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--buO-syXy--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://thepracticaldev.s3.amazonaws.com/i/n14zydidvyv2cwqos6f5.png" alt="SEO result sample" width="800" height="347"&gt;&lt;/a&gt;&lt;br&gt;
Currently, SEO understands those pages but I think that it's not common behavior. If you request a page you wait to that page return structured information about what is it. Which brings me to the next point...&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;It's not normal behavior to the browser&lt;/strong&gt;&lt;br&gt;
If you, sometimes, had set up manually an SPA you discovered the 404 issues on AngularJS. If you want to remove the '#' of the URL to simulate the real URL, you need a node server that on all cases send the main HTML file. &lt;br&gt;
All browsers expect that when the user uses a URL, that loads content. So if browsers received &lt;em&gt;falsy empty&lt;/em&gt; content, it's so weird.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Memory leaks&lt;/strong&gt;&lt;br&gt;
Having the same page loaded for a long time can cause considerable problems with your computer memory (browser crash, issues with the power battery, etc) &lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Tricky browser loading indicators&lt;/strong&gt;&lt;br&gt;
If the browser indicator says that the page completes the load, you would be sure that the page is ready. But is not the case to SPA pages.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Server-Side Rendering (SSR)
&lt;/h2&gt;

&lt;p&gt;With Node appears the possibility to run JavaScript from the server.&lt;/p&gt;

&lt;p&gt;So, we could use it to create better web apps. But.. could we run our beautiful UI frameworks form the server? Yep, we can.&lt;/p&gt;

&lt;h3&gt;
  
  
  Only Server Side
&lt;/h3&gt;

&lt;p&gt;If you want to render React from the server you have to use react-dom/server with a utils function, renderToString. Check this sample:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--npZ241QK--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://thepracticaldev.s3.amazonaws.com/i/xqranf5qb6lsism7217f.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--npZ241QK--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://thepracticaldev.s3.amazonaws.com/i/xqranf5qb6lsism7217f.png" alt="only server-side example" width="800" height="314"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Easy right? Well, not. &lt;/p&gt;

&lt;p&gt;This is only the first part, if you need to handle an event or change the DOM, this doesn't work. The function name says all that you need to know, this creates a string with the HTML and sends the initial view to the client, despite using React this app is not reactive.&lt;/p&gt;

&lt;h3&gt;
  
  
  Server Side World
&lt;/h3&gt;

&lt;p&gt;If you want to be this App reactive, you need to use &lt;strong&gt;hydrate&lt;/strong&gt; React function. Instead of using render, that creates a DOM, you should use hydrate, that matches a DOM with VDOM on React. &lt;/p&gt;

&lt;p&gt;For more information, you could check on React &lt;a href="https://reactjs.org/docs/react-dom.html#hydrate"&gt;documentation&lt;/a&gt;. &lt;/p&gt;

&lt;p&gt;All &lt;strong&gt;SSR&lt;/strong&gt; frameworks use a similar behavior. For sample on &lt;a href="https://github.com/zeit/next.js/blob/cffa2e3f2165b58b77fb354d3f74a4ac8222b68f/packages/next/client/index.js#L246"&gt;this&lt;/a&gt; code lines on &lt;a href="https://nextjs.org/"&gt;Next&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--H2cVCkCc--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://thepracticaldev.s3.amazonaws.com/i/pu4epfgyw134qw9fmyi8.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--H2cVCkCc--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://thepracticaldev.s3.amazonaws.com/i/pu4epfgyw134qw9fmyi8.png" alt="hydrate example" width="800" height="314"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Isomorphic Apps
&lt;/h3&gt;

&lt;p&gt;With all this knowledge on your head, let me explain what is isomorphic apps. If we see the app wrapper on a SPA we should see something like that:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--FOcSH_a_--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://thepracticaldev.s3.amazonaws.com/i/onu5a8iwqaw5mprir19s.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--FOcSH_a_--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://thepracticaldev.s3.amazonaws.com/i/onu5a8iwqaw5mprir19s.png" alt="isomorphic apps" width="800" height="502"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;We only change the common render function by a hydrate function. This code will run on the client.  We create a little server with the following code...&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--nTohyiXc--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://thepracticaldev.s3.amazonaws.com/i/vif90zxjhifoemgbehfs.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--nTohyiXc--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://thepracticaldev.s3.amazonaws.com/i/vif90zxjhifoemgbehfs.png" alt="server side configuration" width="800" height="484"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;In this case, the app will render on first time by the location that the server received on the request. This creates an isomorphic router, the first rendering populates the request URL as a router URL. But when the app is loaded,  the route is managed by the client.&lt;/p&gt;

&lt;h3&gt;
  
  
  The Future
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--t8yIsoUC--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://thepracticaldev.s3.amazonaws.com/i/bzj3vrmx8eqf8mk9a72r.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--t8yIsoUC--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://thepracticaldev.s3.amazonaws.com/i/bzj3vrmx8eqf8mk9a72r.png" alt="state propagation from server to client" width="800" height="636"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;When you need to propagate the state from the server to the client. You could implement something like the image.&lt;/p&gt;

&lt;p&gt;In these cases and others, re-hydration has a considerable cost. Because we need to propagate the data from all the VDOM. &lt;/p&gt;

&lt;p&gt;Some people propose some solutions to solve these issues. &lt;/p&gt;

&lt;p&gt;These ideas are about reducing the scope to hydrate the app. We could hydrate by events or only hydrate the visible part on the browser, like lazy-hydration (&lt;a href="https://github.com/hadeeb/react-lazy-hydration"&gt;check that GitHub repo&lt;/a&gt;).&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;That's all folks, thanks for reading.&lt;/strong&gt;&lt;/p&gt;

</description>
      <category>react</category>
      <category>webdev</category>
      <category>story</category>
    </item>
  </channel>
</rss>
