<?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: Sarmun Bustillo</title>
    <description>The latest articles on DEV Community by Sarmun Bustillo (@sarmunbustillo).</description>
    <link>https://dev.to/sarmunbustillo</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%2F724437%2F52e202cd-825d-46bb-b847-fc6f47b64574.png</url>
      <title>DEV Community: Sarmun Bustillo</title>
      <link>https://dev.to/sarmunbustillo</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/sarmunbustillo"/>
    <language>en</language>
    <item>
      <title>Card reveal on hover</title>
      <dc:creator>Sarmun Bustillo</dc:creator>
      <pubDate>Sun, 27 Nov 2022 06:56:50 +0000</pubDate>
      <link>https://dev.to/sarmunbustillo/card-reveal-on-hover-36id</link>
      <guid>https://dev.to/sarmunbustillo/card-reveal-on-hover-36id</guid>
      <description>&lt;p&gt;Let's create a hover effect to incrementally reveal the card's content.&lt;/p&gt;

&lt;p&gt;This effect is pretty simple, within the card we have 2 things, the content and the 'spotlight' or circle. The trick is to make the spotlight to follow the cursor within the card's bounds and the more it moves the bigger it gets.&lt;/p&gt;

&lt;h2&gt;
  
  
  Functionality
&lt;/h2&gt;

&lt;p&gt;So for each card we want to listen for any mouse movement. let's create a function for that:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;function onHoverCard(card) {
    const cardSpotlight = card.querySelector('.card__spotlight');
    let size = 50;

    card.addEventListener('mousemove', (e) =&amp;gt; {
        const { x, y } = card.getBoundingClientRect();
        const mouseX = e.clientX - x;
        const mouseY = e.clientY - y;
        const cardSpotlightX = mouseX - cardSpotlight.offsetWidth / 2;
        const cardSpotlightY = mouseY - cardSpotlight.offsetHeight / 2;

        size += 2.5;
        cardSpotlight.style.setProperty('--_spotlight-size', `${size}px`);

        cardSpotlight.style.transform = `translate(${cardSpotlightX}px, ${cardSpotlightY}px)`;
    });

    card.addEventListener('mouseleave', () =&amp;gt; {
        size = 50;
    });
}

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

&lt;/div&gt;



&lt;p&gt;To attach the spotlight element to the mouse within the card's bounds, we first need to find the card's &lt;strong&gt;&lt;em&gt;x&lt;/em&gt;&lt;/strong&gt; and &lt;strong&gt;&lt;em&gt;Y&lt;/em&gt;&lt;/strong&gt; coords in relation to the page. Then we find the current &lt;strong&gt;&lt;em&gt;x&lt;/em&gt;&lt;/strong&gt; and &lt;strong&gt;&lt;em&gt;y&lt;/em&gt;&lt;/strong&gt; coords from the mouse event being fired. With those we can calculate the spotlight's coords. Well, just to make the spotlight right in the middle of the cursor we need to deduct half of its size from the coords. Finally, we use the CSS transform property to move the element to the correct coords.&lt;/p&gt;

&lt;p&gt;To make the spotlight grow we increment its size everytime the mouse moves and we reset it when the mouse leaves the card. We do this by keeping track of its current size with a variable (&lt;strong&gt;size&lt;/strong&gt;).&lt;/p&gt;

&lt;p&gt;Aaaand that is pretty much it!&lt;/p&gt;

&lt;p&gt;Here is a &lt;a href="https://codepen.io/sarmunbustillo/pen/XWYYRVw" rel="noopener noreferrer"&gt;demo&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://twitter.com/sarmunbustillo?t=pztqXmT7DH2pa9lDLjfrdQ&amp;amp;s=09" rel="noopener noreferrer"&gt;My Twitter&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://www.sarmunbustillo.com/blog" rel="noopener noreferrer"&gt;Checkout my blog &lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Thank you!&lt;/p&gt;

</description>
      <category>braziliandevs</category>
    </item>
    <item>
      <title>Stacking elements</title>
      <dc:creator>Sarmun Bustillo</dc:creator>
      <pubDate>Sat, 17 Sep 2022 12:26:36 +0000</pubDate>
      <link>https://dev.to/sarmunbustillo/stacking-elements-180l</link>
      <guid>https://dev.to/sarmunbustillo/stacking-elements-180l</guid>
      <description>&lt;p&gt;With modern CSS is very easy to stack elements on top of each other, without much code and can easily be extended with more functionality.&lt;/p&gt;

&lt;h2&gt;
  
  
  CSS Grid
&lt;/h2&gt;

&lt;p&gt;With CSS Grid we can create customizable grids and assign its items to specific rows and columns. We will take advantage of this to stack our elements. &lt;/p&gt;

&lt;p&gt;Let's the following cards as an example:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--pLrtguqH--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/8lrzay4k3larsr89a3qw.jpeg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--pLrtguqH--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/8lrzay4k3larsr89a3qw.jpeg" alt="Unstacked Cards" width="880" height="406"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;First, we make the card's container a &lt;strong&gt;&lt;em&gt;grid container&lt;/em&gt;&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;.cards {
    display: grid;
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Next, we explicitly set all the cards into the &lt;strong&gt;same&lt;/strong&gt; column and the row.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;.card {
    grid-row: 1;
    grid-column: 1;
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;And guess what, that is it!&lt;/p&gt;

&lt;p&gt;Buuuuuut! let me show you with something really simple how easy is to add extra styling.&lt;/p&gt;

&lt;h3&gt;
  
  
  A bit of offset
&lt;/h3&gt;

&lt;p&gt;So the user can see that the cards are stacked up, let's add a bit of offset. In this example we will go the difficult route, we dont know how many elements (cards) are to be stacked up. So we cant just use CSS, we need to add a bit of JavaScript to dynamically add the offset.&lt;/p&gt;

&lt;p&gt;Let's update our card's CSS&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;.card {
    grid-row: 1;
    grid-column: 1;

    // new lines
  position: relative;
  top:  var(--_card-offset);
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;And With JavaScript we will update our CSS var.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const cards = document.querySelectorAll(".card");
const OFFSET_VALUE: 30;

cards.forEach((card, i) =&amp;gt; {
  card.style.setProperty(`--_card-offset`, `${OFFSET_VALUE * i}px`);
})
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In a nutshell, each card will be 30px lower than the one before.&lt;/p&gt;

&lt;p&gt;Now you can for example set the card's &lt;strong&gt;z-index&lt;/strong&gt; to a higher value whenever it gets hovered so it comes to the front.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;.card:hover {
    z-index: 2;
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Following this same pattern it is very easy to exented the styles and functionality of our stacking elements.&lt;/p&gt;

&lt;p&gt;Thank you! &lt;/p&gt;

&lt;p&gt;&lt;a href="https://codepen.io/sarmunbustillo/pen/MWGpGaW"&gt;Demo&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://twitter.com/sarmunbustillo?t=pztqXmT7DH2pa9lDLjfrdQ&amp;amp;s=09"&gt;My Twitter&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://www.sarmunbustillo.com/blog"&gt;Checkout my blog &lt;/a&gt;&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>webdev</category>
      <category>css</category>
      <category>programming</category>
    </item>
    <item>
      <title>Typescript Series -Utility Type ReturnType</title>
      <dc:creator>Sarmun Bustillo</dc:creator>
      <pubDate>Thu, 08 Sep 2022 09:52:09 +0000</pubDate>
      <link>https://dev.to/sarmunbustillo/typescript-series-utility-type-returntype-20hn</link>
      <guid>https://dev.to/sarmunbustillo/typescript-series-utility-type-returntype-20hn</guid>
      <description>&lt;p&gt;I'd like to start by saying that I am doing this series to learn and understand better Typescript, so feel free to correct me or contact me.&lt;/p&gt;

&lt;h2&gt;
  
  
  ReturnType&amp;lt;Type&amp;gt;
&lt;/h2&gt;

&lt;p&gt;Constructs a type consisting of the return type of function Type.&lt;/p&gt;

&lt;p&gt;Let's see some examples:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;type T0 = ReturnType&amp;lt;() =&amp;gt; string&amp;gt;; //string

type T1 = ReturnType&amp;lt;(s: string) =&amp;gt; void&amp;gt;; // void

type T2 = ReturnType&amp;lt;&amp;lt;T&amp;gt;() =&amp;gt; T&amp;gt;; // unknown

type T3 = ReturnType&amp;lt;&amp;lt;T extends U, U extends number[]&amp;gt;() =&amp;gt; T&amp;gt;; // numver[]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  So what do we know so far?
&lt;/h3&gt;

&lt;p&gt;Our type should:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt; Receive a function&lt;/li&gt;
&lt;li&gt; Infer and return the returning type of that function if there is any&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Let's see the type.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;type MyReturnType&amp;lt;T&amp;gt; = T extends (...args: any) =&amp;gt; infer R ? R : any;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Let's break it down
&lt;/h3&gt;

&lt;p&gt;We accept a type &lt;strong&gt;T&lt;/strong&gt; and we check that type extends a function and if it returns something &lt;strong&gt;T extends (...args: any) =&amp;gt; ...&lt;/strong&gt;&lt;/p&gt;

&lt;h4&gt;
  
  
  Understanding the infer keyword
&lt;/h4&gt;

&lt;p&gt;The infer keyword can be used within a condition in a conditional type to put the inferred type into a variable. That inferred variable can then be used within the conditional branches.&lt;/p&gt;

&lt;p&gt;If the function returns something then we &lt;strong&gt;infer&lt;/strong&gt; its type and we return that &lt;strong&gt;... =&amp;gt; infer R ? R ...&lt;/strong&gt; otherwise, it could be anything or nothing, so we return any &lt;strong&gt;... : any&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;That is it, thank you!&lt;/p&gt;

&lt;p&gt;you can find me here &lt;a href="https://twitter.com/sarmunbustillo?t=pztqXmT7DH2pa9lDLjfrdQ&amp;amp;s=09"&gt;My Twitter&lt;/a&gt;&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>typescript</category>
      <category>webdev</category>
      <category>programming</category>
    </item>
    <item>
      <title>Typescript Series - Parameters Utility Type</title>
      <dc:creator>Sarmun Bustillo</dc:creator>
      <pubDate>Sun, 28 Aug 2022 19:41:48 +0000</pubDate>
      <link>https://dev.to/sarmunbustillo/typescript-series-parameters-utility-type-26ib</link>
      <guid>https://dev.to/sarmunbustillo/typescript-series-parameters-utility-type-26ib</guid>
      <description>&lt;p&gt;I'd like to start by saying that I am doing this series to learn and understand better Typescript, so feel free to correct me or contact me.&lt;/p&gt;

&lt;h2&gt;
  
  
  Parameters
&lt;/h2&gt;

&lt;p&gt;Constructs a tuple type from the types used in the parameters of a function type &lt;em&gt;Type&lt;/em&gt;.&lt;/p&gt;

&lt;p&gt;Examples:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;type T0 = Parameters&amp;lt;() =&amp;gt; string&amp;gt; // []
type T1 = Parameters&amp;lt;(s: string) =&amp;gt; void&amp;gt; // [s: string]
type T2 = Parameters&amp;lt;&amp;lt;T&amp;gt;(arg: T) =&amp;gt; T&amp;gt; // [arg: unknown]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;That means our type should look something like&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const foo = (arg1: string, arg2: number): void =&amp;gt; {}
const bar = (arg1: boolean, arg2: { a: 'A' }): void =&amp;gt; {}
const baz = (): void =&amp;gt; {}

MyParameters&amp;lt;typeof foo&amp;gt; // [string, number]
MyParameters&amp;lt;typeof bar&amp;gt; // [boolean, { a: 'A' }]
MyParameters&amp;lt;typeof baz&amp;gt; // []
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Ok so what do we know so far:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Receives a function&lt;/li&gt;
&lt;li&gt;Infer the types of the function parameters passed&lt;/li&gt;
&lt;li&gt;Return a tuple of the types of the function parameters, if any (no pun intended) or nothing
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;type MyParameters&amp;lt;T extends (...args: any[]) =&amp;gt; any&amp;gt; = T extends (...args: infer R ) =&amp;gt; unknown ? R : never
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Let's break it down:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;T extends (...args: any[]) =&amp;gt; any&lt;/code&gt; You could read this as our type extends a function and could return anything or nothing.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Understanding the infer keyword&lt;/strong&gt;&lt;br&gt;
The infer keyword can be used within a condition in a conditional type to put the inferred type into a variable. That inferred variable can then be used within the conditional branches.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;T extends (...args: infer R ) =&amp;gt; unknown ? R : never&lt;/code&gt; So we infer the types of the function parameters. If it does return something, meaning there were parameters, we return the inferred type, otherwise we return never (nothing, ignored by TS)&lt;/p&gt;

&lt;p&gt;Thank you!&lt;/p&gt;

&lt;p&gt;you can find me here &lt;a href="https://twitter.com/sarmunbustillo?t=pztqXmT7DH2pa9lDLjfrdQ&amp;amp;s=09"&gt;My Twitter&lt;/a&gt;&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>typescript</category>
      <category>webdev</category>
      <category>beginners</category>
    </item>
    <item>
      <title>Typescript Series - Array Unshift Type</title>
      <dc:creator>Sarmun Bustillo</dc:creator>
      <pubDate>Fri, 26 Aug 2022 16:46:03 +0000</pubDate>
      <link>https://dev.to/sarmunbustillo/typescript-series-array-unshift-type-5c5e</link>
      <guid>https://dev.to/sarmunbustillo/typescript-series-array-unshift-type-5c5e</guid>
      <description>&lt;p&gt;I'd like to start by saying that I am doing this series to learn and understand better Typescript, so feel free to correct me or contact me.&lt;/p&gt;

&lt;p&gt;Let's create a type for the JavaScript Array.unshift function. Which takes pushes an element into the array in the last position.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Unshift&amp;lt;[1, 2], 0&amp;gt; // [0, 1, 2,]
Unshift&amp;lt;['1', 2, '3'], boolean&amp;gt; \\ [boolean, '1', 2, '3']
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;So we know we have an array and our type should return the new value + array.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;type Unshift&amp;lt;TArray extends unknown[], U&amp;gt; = [U, ...TArray]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;code&gt;TArray extends readonly unknown[]&lt;/code&gt; We first check our TArray is of type array.&lt;/p&gt;

&lt;p&gt;Then we pass the value and we spread the array into an array &lt;code&gt;[U, ...TArray]&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Thank you!&lt;/p&gt;

&lt;p&gt;you can find me here &lt;a href="https://twitter.com/sarmunbustillo?t=pztqXmT7DH2pa9lDLjfrdQ&amp;amp;s=09"&gt;My Twitter&lt;/a&gt;&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>typescript</category>
      <category>webdev</category>
      <category>postgres</category>
    </item>
    <item>
      <title>Typescript Series - Array Push Type</title>
      <dc:creator>Sarmun Bustillo</dc:creator>
      <pubDate>Thu, 25 Aug 2022 17:23:07 +0000</pubDate>
      <link>https://dev.to/sarmunbustillo/typescript-series-array-includes-type-3pl4</link>
      <guid>https://dev.to/sarmunbustillo/typescript-series-array-includes-type-3pl4</guid>
      <description>&lt;p&gt;I'd like to start by saying that I am doing this series to learn and understand better Typescript, so feel free to correct me or contact me.&lt;/p&gt;

&lt;p&gt;Let's create a type for the JavaScript Array.push function. Which takes pushes an element into the array in the last position.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Push&amp;lt;[1, 2], '3'&amp;gt; // [1, 2, '3']
Push&amp;lt;['1', 2, '3'], boolean&amp;gt; // ['1', 2, '3', boolean]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;So we know we have an array and our type should return an array + the new value.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;type Push&amp;lt;TArray extends unknown[], U&amp;gt; = [...TArray, U]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;code&gt;TArray extends readonly unknown[]&lt;/code&gt; We first check our TArray is of type array.&lt;/p&gt;

&lt;p&gt;then we simply spread the array and the new value into an array &lt;code&gt;[...TArray, U]&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Thank you!&lt;/p&gt;

&lt;p&gt;you can find me here &lt;a href="https://twitter.com/sarmunbustillo?t=pztqXmT7DH2pa9lDLjfrdQ&amp;amp;s=09"&gt;My Twitter&lt;/a&gt;&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>typescript</category>
      <category>webdev</category>
      <category>tutorial</category>
    </item>
    <item>
      <title>Typescript Series - Array Includes Type</title>
      <dc:creator>Sarmun Bustillo</dc:creator>
      <pubDate>Wed, 24 Aug 2022 14:14:01 +0000</pubDate>
      <link>https://dev.to/sarmunbustillo/typescript-series-array-includes-type-4dgm</link>
      <guid>https://dev.to/sarmunbustillo/typescript-series-array-includes-type-4dgm</guid>
      <description>&lt;p&gt;I'd like to start by saying that I am doing this series to learn and understand better Typescript, so feel free to correct me or contact me.&lt;/p&gt;

&lt;p&gt;Let's create a type for the JavaScript Array.includes function in the type system. A type takes the two arguments. The output should be a boolean true or false.&lt;/p&gt;

&lt;p&gt;The JavaScript Array.includes function looks like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const arr = ["a","b","c"]:
arr.includes("a") // true
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;And our type should should look something like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;Includes&amp;lt;[1, 2, 3, 5, 6, 7], 7&amp;gt; // true
&amp;lt;Includes&amp;lt;[1, 2, 3, 5, 6, 7], 4&amp;gt; // false
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  So what do we know?
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;We know that our type should take an array and a value as inputs. &lt;/li&gt;
&lt;li&gt;We should take check if the desired value exist in the array &lt;/li&gt;
&lt;li&gt;After checking against every element in the array, we return a boolean accordingly.
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;type Includes&amp;lt;TArray extends readonly unknown[], Value&amp;gt; = 
TArray extends [infer FIRST,... infer REST] ? 
Equal&amp;lt;Value,FIRST&amp;gt; extends true ? true : Includes&amp;lt;REST,Value&amp;gt; : false
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;For this type we need to the Equal utility type which checks if two inputs are equal.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;TArray extends readonly unknown[]&lt;/code&gt; We first check our TArray is of type array. &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Understanding the infer keyword&lt;/strong&gt;&lt;br&gt;
The infer keyword can be used within a condition in a conditional type to put the inferred type into a variable. That inferred variable can then be used within the conditional branches.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;TArray extends [infer FIRST,... infer REST]&lt;/code&gt; We infer the first element of the array and then rest of elements.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;Equal&amp;lt;Value,FIRST&amp;gt; extends true&lt;/code&gt; We check if that first element is equal to our desired value, if so, we got it and therefore we should return true. Otherwise we recursively check again with the rest of the elements &lt;code&gt;: Includes&amp;lt;REST,Value&amp;gt;&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Lastly, if the element is not to be found in the array we return false &lt;code&gt;: false&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;This one was a tough one, but we learned how The includes function works under the hood.&lt;/p&gt;

&lt;p&gt;Thank you!&lt;/p&gt;

&lt;p&gt;you can find me here &lt;a href="https://twitter.com/sarmunbustillo?t=pztqXmT7DH2pa9lDLjfrdQ&amp;amp;s=09"&gt;My Twitter&lt;/a&gt;&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>typescript</category>
      <category>webdev</category>
      <category>programming</category>
    </item>
    <item>
      <title>Typescript Series - Array Concat Type</title>
      <dc:creator>Sarmun Bustillo</dc:creator>
      <pubDate>Tue, 23 Aug 2022 13:43:49 +0000</pubDate>
      <link>https://dev.to/sarmunbustillo/typescript-series-array-concat-type-4j22</link>
      <guid>https://dev.to/sarmunbustillo/typescript-series-array-concat-type-4j22</guid>
      <description>&lt;p&gt;I'd like to start by saying that I am doing this series to learn and understand better Typescript, so feel free to correct me or contact me.&lt;/p&gt;

&lt;p&gt;Let's create a type for the JavaScript Array.concat function. A type takes the two arguments. The output should be a new array that includes inputs in ltr order.&lt;/p&gt;

&lt;p&gt;Some examples:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Concat&amp;lt;[], []&amp;gt;
// []

Concat&amp;lt;[], [1]&amp;gt;
// [1]

Concat&amp;lt;[1, 2], [3, 4]&amp;gt;,
// [1, 2, 3, 4]

Concat&amp;lt;['1', 2, '3'], [false, boolean, '4']&amp;gt;
// ['1', 2, '3', false, boolean, '4']
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;So we know that our inputs should be arrays as well as the return type.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;type Concat&amp;lt;T extends unknown[], U extends unknown[]&amp;gt; = [...T,... U]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;code&gt;&amp;lt;T extends unknown[], U extends unknown[]&amp;gt;&lt;/code&gt; We first check if both of our inputs are arrays. If so, using the spread operator we spread both input values into a new array &lt;code&gt;[...T,... U]&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;And there you go, our concat type is done.&lt;/p&gt;

&lt;p&gt;Thank you!&lt;/p&gt;

&lt;p&gt;you can find me here &lt;a href="https://twitter.com/sarmunbustillo?t=pztqXmT7DH2pa9lDLjfrdQ&amp;amp;s=09"&gt;My Twitter&lt;/a&gt;&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>typescript</category>
      <category>programming</category>
      <category>webdev</category>
    </item>
    <item>
      <title>Typescript Series - If Type Util</title>
      <dc:creator>Sarmun Bustillo</dc:creator>
      <pubDate>Mon, 22 Aug 2022 16:02:45 +0000</pubDate>
      <link>https://dev.to/sarmunbustillo/typescript-series-if-type-util-3lho</link>
      <guid>https://dev.to/sarmunbustillo/typescript-series-if-type-util-3lho</guid>
      <description>&lt;p&gt;I'd like to start by saying that I am doing this series to learn and understand better Typescript, so feel free to correct me or contact me.&lt;/p&gt;

&lt;p&gt;A little challange, let's write an util &lt;em&gt;&lt;strong&gt;If&lt;/strong&gt;&lt;/em&gt; which accepts condition C, a truthy return type T, and a falsy return type F. C is expected to be either true or false while T and F can be any type.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;type A = If&amp;lt;true, 'a', 'b'&amp;gt;  // expected to be 'a'
type B = If&amp;lt;false, 'a', 'b'&amp;gt; // expected to be 'b'
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This one is a simple one, but a good practice&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;type If&amp;lt;C extends boolean, T, F&amp;gt; = C extends true ? T : F
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;We know C is of type boolean so we make sure it extends it, remember, C is expected to be either true or false, so according with our requirements, if C is true we return our type T otherwise we return our falsy type F.&lt;/p&gt;

&lt;p&gt;Thank you!&lt;/p&gt;

&lt;p&gt;you can find me here &lt;a href="https://twitter.com/sarmunbustillo?t=pztqXmT7DH2pa9lDLjfrdQ&amp;amp;s=09"&gt;My Twitter&lt;/a&gt;&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>webdev</category>
      <category>programming</category>
      <category>typescript</category>
    </item>
    <item>
      <title>Typescript Series - Awaited Type</title>
      <dc:creator>Sarmun Bustillo</dc:creator>
      <pubDate>Sun, 21 Aug 2022 14:44:48 +0000</pubDate>
      <link>https://dev.to/sarmunbustillo/typescript-series-awaited-type-29l7</link>
      <guid>https://dev.to/sarmunbustillo/typescript-series-awaited-type-29l7</guid>
      <description>&lt;p&gt;I'd like to start by saying that I am doing this series to learn and understand better Typescript, so feel free to correct me or contact me.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;If we have a type which is wrapped type like Promise. How we can get a type which is inside the wrapped type?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Let's see a couple of examples&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;type Example1 = Promise&amp;lt;string&amp;gt;
type Example2 = Promise&amp;lt;{ field: number }&amp;gt;
type Example3 = Promise&amp;lt;Promise&amp;lt;string | number&amp;gt;&amp;gt;


type Result1 = MyAwaited&amp;lt;Example1&amp;gt; // string
type Result2 = MyAwaited&amp;lt;Example2&amp;gt; // { field: number }
type Result3 = MyAwaited&amp;lt;Example3&amp;gt; // string | number

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

&lt;/div&gt;



&lt;p&gt;Worth noticing here, that we should also take nested promises into account.&lt;/p&gt;

&lt;p&gt;How would this type would look like?&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;type MyAwaited&amp;lt;Type&amp;gt; = Type extends Promise&amp;lt;infer K&amp;gt; 
? MyAwaited&amp;lt;K&amp;gt; : Type;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Understanding the infer keyword
&lt;/h3&gt;

&lt;p&gt;The infer keyword can be used within a condition in a conditional type to put the inferred type into a variable. That inferred variable can then be used within the conditional branches.&lt;/p&gt;

&lt;p&gt;Let's break it down:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;Type extends Promise&amp;lt;infer K&amp;gt;&lt;/code&gt; Here we check if Type extends a Promise type and we &lt;strong&gt;infer&lt;/strong&gt; the type that is wrapped inside.&lt;/p&gt;

&lt;p&gt;If it does extend it, meaning our Type is of type Promise (ex: Promise&amp;gt;), then  we use recursion to check again &lt;code&gt;MyAwaited&amp;lt;K&amp;gt;&lt;/code&gt; &lt;/p&gt;

&lt;p&gt;if it does &lt;strong&gt;not&lt;/strong&gt; extend it, then we just simply return the Type&lt;/p&gt;

&lt;p&gt;Thank you!&lt;/p&gt;

&lt;p&gt;you can find me here &lt;a href="https://twitter.com/sarmunbustillo?t=pztqXmT7DH2pa9lDLjfrdQ&amp;amp;s=09"&gt;My Twitter&lt;/a&gt;&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>webdev</category>
      <category>programming</category>
      <category>typescript</category>
    </item>
    <item>
      <title>Typescript Series - Length of a Tuple</title>
      <dc:creator>Sarmun Bustillo</dc:creator>
      <pubDate>Sat, 20 Aug 2022 14:51:09 +0000</pubDate>
      <link>https://dev.to/sarmunbustillo/typescript-series-length-of-a-tuple-4d8m</link>
      <guid>https://dev.to/sarmunbustillo/typescript-series-length-of-a-tuple-4d8m</guid>
      <description>&lt;p&gt;I'd like to start by saying that I am doing this series to learn and understand better Typescript, so feel free to correct me or contact me.&lt;/p&gt;

&lt;h2&gt;
  
  
  Let's write a Type to get the length of a tuple.
&lt;/h2&gt;

&lt;p&gt;First, what it a tuple, tuple types allow you to express an array with a fixed number of elements whose types are known, but need not be the same. &lt;/p&gt;

&lt;p&gt;Lets have a look to our tuple&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const tesla = ['tesla', 'model 3', 'model X', 'model Y'] as const
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Notice how we define it &lt;em&gt;*&lt;em&gt;as const *&lt;/em&gt;&lt;/em&gt; so it can't be modified.&lt;/p&gt;

&lt;p&gt;Now we need to create a type that expects a tuple, and returns its length.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;type Length&amp;lt;Type extends readonly unknown[]&amp;gt; = Type['length']
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Let's break it down.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;Length&amp;lt;Type extends readonly unknown[]&amp;gt;&lt;/code&gt;&lt;br&gt;
You can read this as, Type extends an array of unknown type that its length won't change, remember for tuples we do know it's length, that is why we define the tuple variable as const so we cant modify it.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;Type['length']&lt;/code&gt; Lastly, we access the length property from our Type.&lt;/p&gt;

&lt;p&gt;This one was an easy one&lt;/p&gt;

&lt;p&gt;Thank you!&lt;/p&gt;

&lt;p&gt;you can find me here &lt;a href="https://twitter.com/sarmunbustillo?t=pztqXmT7DH2pa9lDLjfrdQ&amp;amp;s=09"&gt;My Twitter&lt;/a&gt;&lt;/p&gt;

</description>
      <category>typescript</category>
      <category>javascript</category>
      <category>webdev</category>
      <category>programming</category>
    </item>
    <item>
      <title>Typescript Series - Exclude Utility Type</title>
      <dc:creator>Sarmun Bustillo</dc:creator>
      <pubDate>Fri, 19 Aug 2022 20:07:28 +0000</pubDate>
      <link>https://dev.to/sarmunbustillo/typescript-series-exclude-utility-type-5de6</link>
      <guid>https://dev.to/sarmunbustillo/typescript-series-exclude-utility-type-5de6</guid>
      <description>&lt;p&gt;I'd like to start by saying that I am doing this series to learn and understand better Typescript, so feel free to correct me or contact me.&lt;/p&gt;

&lt;p&gt;Let's write and see how this utility type works under the hood.&lt;/p&gt;

&lt;h2&gt;
  
  
  Exclude
&lt;/h2&gt;

&lt;p&gt;Constructs a type by excluding from UnionType all union members that are assignable to ExcludedMembers (&lt;a href="https://www.typescriptlang.org/docs/handbook/utility-types.html#excludeuniontype-excludedmembers"&gt;docs&lt;/a&gt;)&lt;/p&gt;

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

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;type T0 = Exclude&amp;lt;"a" | "b" | "c", "a"&amp;gt;; 

// type T0 = "b" | "c"

type T1 = Exclude&amp;lt;"a" | "b" | "c", "a" | "b"&amp;gt;; 

//type T1 = "c"

type T2 = Exclude&amp;lt;string | number | (() =&amp;gt; void), Function&amp;gt;; 

// type T2 = string | number
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now that we know how it should behave, let's write the type.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;type MyExclude&amp;lt;Type, Exclude&amp;gt; =  Type extends Exclude 
? never : Type
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Here we check if Type extends Exclude then we should ignore it, remember we want to exclude that element, otherwise return the non-matching value.&lt;/p&gt;

&lt;p&gt;There you go, it was a pretty simple one!&lt;/p&gt;

&lt;p&gt;Thank you!&lt;/p&gt;

&lt;p&gt;you can find me here &lt;a href="https://twitter.com/sarmunbustillo?t=pztqXmT7DH2pa9lDLjfrdQ&amp;amp;s=09"&gt;My Twitter&lt;/a&gt;&lt;/p&gt;

</description>
      <category>typescript</category>
      <category>javascript</category>
      <category>webdev</category>
      <category>programming</category>
    </item>
  </channel>
</rss>
