<?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: Muhammad Ridho Anshory</title>
    <description>The latest articles on DEV Community by Muhammad Ridho Anshory (@ridhoanshory).</description>
    <link>https://dev.to/ridhoanshory</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%2F760033%2F68e6b593-3378-4eca-a0a9-592e8e258795.jpg</url>
      <title>DEV Community: Muhammad Ridho Anshory</title>
      <link>https://dev.to/ridhoanshory</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/ridhoanshory"/>
    <language>en</language>
    <item>
      <title>JSX Element, React Node, React Element</title>
      <dc:creator>Muhammad Ridho Anshory</dc:creator>
      <pubDate>Sat, 12 Mar 2022 00:12:52 +0000</pubDate>
      <link>https://dev.to/ridhoanshory/jsx-element-react-node-react-element-idi</link>
      <guid>https://dev.to/ridhoanshory/jsx-element-react-node-react-element-idi</guid>
      <description>&lt;p&gt;I am currently migrating a React application to TypeScript. So far, this works pretty well, but I have a problem with the return types of my &lt;code&gt;render&lt;/code&gt; functions, specifically in my functional components.&lt;/p&gt;

&lt;p&gt;Cut a long story short, I have these questions during my learning process:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;What is the difference between &lt;code&gt;JSX.Element&lt;/code&gt;, &lt;code&gt;ReactNode&lt;/code&gt; and &lt;code&gt;ReactElement&lt;/code&gt;?&lt;/li&gt;
&lt;li&gt;Why do the &lt;code&gt;render&lt;/code&gt; methods of class components return &lt;code&gt;ReactNode&lt;/code&gt;, but functional components return &lt;code&gt;ReactElement&lt;/code&gt;?&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  What is the difference between &lt;code&gt;JSX.Element&lt;/code&gt;, &lt;code&gt;ReactNode&lt;/code&gt; and &lt;code&gt;ReactElement&lt;/code&gt;?
&lt;/h2&gt;

&lt;p&gt;A ReactElement is an object with a type and props.&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="nx"&gt;type&lt;/span&gt; &lt;span class="nx"&gt;Key&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;string&lt;/span&gt; &lt;span class="o"&gt;|&lt;/span&gt; &lt;span class="nx"&gt;number&lt;/span&gt;

 &lt;span class="kr"&gt;interface&lt;/span&gt; &lt;span class="nx"&gt;ReactElement&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;P&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;any&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;T&lt;/span&gt; &lt;span class="kd"&gt;extends&lt;/span&gt; &lt;span class="nx"&gt;string&lt;/span&gt; &lt;span class="o"&gt;|&lt;/span&gt; &lt;span class="nx"&gt;JSXElementConstructor&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;any&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;string&lt;/span&gt; &lt;span class="o"&gt;|&lt;/span&gt; &lt;span class="nx"&gt;JSXElementConstructor&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;any&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="na"&gt;type&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;T&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="nl"&gt;props&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;P&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="nl"&gt;key&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;Key&lt;/span&gt; &lt;span class="o"&gt;|&lt;/span&gt; &lt;span class="kc"&gt;null&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;A ReactNode is a ReactElement, a ReactFragment, a string, a number or an array of ReactNodes, or null, or undefined, or a boolean:&lt;/p&gt;

&lt;p&gt;A ReactNode is a ReactElement, a ReactFragment, a string, a number or an array of ReactNodes, or null, or undefined, or a boolean:&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="nx"&gt;type&lt;/span&gt; &lt;span class="nx"&gt;ReactText&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;string&lt;/span&gt; &lt;span class="o"&gt;|&lt;/span&gt; &lt;span class="nx"&gt;number&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="nx"&gt;type&lt;/span&gt; &lt;span class="nx"&gt;ReactChild&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;ReactElement&lt;/span&gt; &lt;span class="o"&gt;|&lt;/span&gt; &lt;span class="nx"&gt;ReactText&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="kr"&gt;interface&lt;/span&gt; &lt;span class="nx"&gt;ReactNodeArray&lt;/span&gt; &lt;span class="kd"&gt;extends&lt;/span&gt; &lt;span class="nb"&gt;Array&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;ReactNode&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{}&lt;/span&gt;
&lt;span class="nx"&gt;type&lt;/span&gt; &lt;span class="nx"&gt;ReactFragment&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{}&lt;/span&gt; &lt;span class="o"&gt;|&lt;/span&gt; &lt;span class="nx"&gt;ReactNodeArray&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="nx"&gt;type&lt;/span&gt; &lt;span class="nx"&gt;ReactNode&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;ReactChild&lt;/span&gt; &lt;span class="o"&gt;|&lt;/span&gt; &lt;span class="nx"&gt;ReactFragment&lt;/span&gt; &lt;span class="o"&gt;|&lt;/span&gt; &lt;span class="nx"&gt;ReactPortal&lt;/span&gt; &lt;span class="o"&gt;|&lt;/span&gt; &lt;span class="nx"&gt;boolean&lt;/span&gt; &lt;span class="o"&gt;|&lt;/span&gt; &lt;span class="kc"&gt;null&lt;/span&gt; &lt;span class="o"&gt;|&lt;/span&gt; &lt;span class="kc"&gt;undefined&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;JSX.Element is a ReactElement, with the generic type for props and type being any. It exists, as various libraries can implement JSX in their own way, therefore JSX is a global namespace that then gets set by the library, React sets it like this:&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="nx"&gt;declare&lt;/span&gt; &lt;span class="nb"&gt;global&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nx"&gt;namespace&lt;/span&gt; &lt;span class="nx"&gt;JSX&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="kr"&gt;interface&lt;/span&gt; &lt;span class="nx"&gt;Element&lt;/span&gt; &lt;span class="kd"&gt;extends&lt;/span&gt; &lt;span class="nx"&gt;React&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;ReactElement&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;any&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;any&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="p"&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;By 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="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nt"&gt;p&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="err"&gt;-&lt;/span&gt; &lt;span class="na"&gt;ReactElement&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="na"&gt;JSX&lt;/span&gt;&lt;span class="err"&gt;.&lt;/span&gt;&lt;span class="na"&gt;Element&lt;/span&gt;
   &lt;span class="err"&gt;&amp;lt;&lt;/span&gt;&lt;span class="na"&gt;Custom&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="err"&gt;-&lt;/span&gt; &lt;span class="na"&gt;ReactElement&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="na"&gt;JSX&lt;/span&gt;&lt;span class="err"&gt;.&lt;/span&gt;&lt;span class="na"&gt;Element&lt;/span&gt;
     &lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="kc"&gt;true&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;test&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt; &lt;span class="c1"&gt;// &amp;lt;- ReactNode&lt;/span&gt;
  &lt;span class="err"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="na"&gt;Custom&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;p&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Why do the &lt;code&gt;render&lt;/code&gt; methods of class components return &lt;code&gt;ReactNode&lt;/code&gt;, but functional components return &lt;code&gt;ReactElement&lt;/code&gt;?
&lt;/h2&gt;

&lt;p&gt;they do return different things. &lt;code&gt;Components&lt;/code&gt; return:&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="nx"&gt;render&lt;/span&gt;&lt;span class="p"&gt;():&lt;/span&gt; &lt;span class="nx"&gt;ReactNode&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;tl;dr:&lt;/strong&gt; It is a current TS type incompatibility &lt;a href="https://github.com/microsoft/TypeScript/issues/21699"&gt;not related to core React&lt;/a&gt;.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;TS class component: returns &lt;code&gt;ReactNode&lt;/code&gt; with &lt;code&gt;render()&lt;/code&gt;, more permissive than React/JS&lt;/li&gt;
&lt;li&gt;TS function component: returns &lt;code&gt;JSX.Element | null&lt;/code&gt;, more restrictive than React/JS&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;In principle, &lt;code&gt;render()&lt;/code&gt; in React/JS class components &lt;a href="https://github.com/facebook/react/issues/12155#issuecomment-363089187"&gt;supports the same return types&lt;/a&gt; as a function component. With regard to TS, the different types are a type inconsistency still kept due to historical reasons and the need for backwards compatibility.&lt;/p&gt;

&lt;p&gt;Ideally a &lt;a href="https://reactjs.org/docs/react-component.html#render"&gt;valid return type&lt;/a&gt; would probably look more like this:&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="nx"&gt;type&lt;/span&gt; &lt;span class="nx"&gt;ComponentReturnType&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;ReactElement&lt;/span&gt; &lt;span class="o"&gt;|&lt;/span&gt; &lt;span class="nb"&gt;Array&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;ComponentReturnType&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="o"&gt;|&lt;/span&gt; &lt;span class="nx"&gt;string&lt;/span&gt; &lt;span class="o"&gt;|&lt;/span&gt; &lt;span class="nx"&gt;number&lt;/span&gt;
  &lt;span class="o"&gt;|&lt;/span&gt; &lt;span class="nx"&gt;boolean&lt;/span&gt; &lt;span class="o"&gt;|&lt;/span&gt; &lt;span class="kc"&gt;null&lt;/span&gt; &lt;span class="c1"&gt;// Note: undefined is invalid&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If you guys have other thoughts leave a comment I'll update the post base on your solutions as well.. cheers🍻&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>beginners</category>
      <category>react</category>
      <category>typescript</category>
    </item>
    <item>
      <title>Git Basic Commands</title>
      <dc:creator>Muhammad Ridho Anshory</dc:creator>
      <pubDate>Sun, 20 Feb 2022 23:07:19 +0000</pubDate>
      <link>https://dev.to/ridhoanshory/git-basic-commands-6ee</link>
      <guid>https://dev.to/ridhoanshory/git-basic-commands-6ee</guid>
      <description>&lt;h1&gt;
  
  
  About this article
&lt;/h1&gt;

&lt;p&gt;In this article, I will share with you guys what are the basic commands when using git CLI.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;I know who did what, when, and why. -Git&lt;/p&gt;
&lt;/blockquote&gt;

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

&lt;ol&gt;
&lt;li&gt;Git: configurations&lt;/li&gt;
&lt;li&gt;Git: starting a repository&lt;/li&gt;
&lt;li&gt;Git: staging files&lt;/li&gt;
&lt;li&gt;Git: committing to a repository&lt;/li&gt;
&lt;li&gt;Git: pulling and pushing from and to repositories&lt;/li&gt;
&lt;li&gt;Git: branching&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  Git: configurations
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;git config &amp;lt;followed with&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;followed with:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nt"&gt;--global&lt;/span&gt; user.name &lt;span class="s2"&gt;"FirstName LastName"&lt;/span&gt;
&lt;span class="nt"&gt;--global&lt;/span&gt; user.name &lt;span class="s2"&gt;"yourEmail@email.com"&lt;/span&gt;
&lt;span class="nt"&gt;--global&lt;/span&gt; color.ui &lt;span class="nb"&gt;true&lt;/span&gt;
&lt;span class="nt"&gt;--list&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Git: starting a repository
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;git init
git status
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Git: staging files
&lt;/h2&gt;

&lt;p&gt;adding files to staging area&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;git add &amp;lt;fileName&amp;gt;
git add &amp;lt;fileName&amp;gt; &amp;lt;anotherFileName&amp;gt;
git add &lt;span class="nb"&gt;.&lt;/span&gt;
git add &lt;span class="nt"&gt;--all&lt;/span&gt;
git add &lt;span class="nt"&gt;-A&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;removes a file from the staging area&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;git &lt;span class="nb"&gt;rm&lt;/span&gt; &lt;span class="nt"&gt;--cached&lt;/span&gt; &amp;lt;fileName&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;discard change or reset the file&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;git reset &amp;lt;fileName&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Git: committing to a repository
&lt;/h2&gt;

&lt;p&gt;Appendix: &lt;/p&gt;

&lt;p&gt;-m → stands for a message&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;git commit &lt;span class="nt"&gt;-m&lt;/span&gt; &lt;span class="s2"&gt;"Add three files"&lt;/span&gt;

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

&lt;/div&gt;



&lt;p&gt;undo the last Git commit&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;git reset &lt;span class="nt"&gt;--soft&lt;/span&gt; HEAD^
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Git: pulling and pushing from and to repositories
&lt;/h2&gt;

&lt;p&gt;Appendix:&lt;/p&gt;

&lt;p&gt;-u → add upstream (tracking) reference&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;git remote add origin &amp;lt;&lt;span class="nb"&gt;link&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; //Adding a remote repository
git push &lt;span class="nt"&gt;-u&lt;/span&gt; origin master //pushes all your branches to the origin.
git clone &amp;lt;cloneURL&amp;gt; // clone a repository
git pull // download all the changes 
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Git: branching
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;git branch // current branch
git branch &amp;lt;branchName&amp;gt; // create a branch
git checkout &amp;lt;branchName&amp;gt; // change current branch
git merge &amp;lt;branchName&amp;gt; // merge branchName to current branch
git checkout &lt;span class="nt"&gt;-b&lt;/span&gt; &amp;lt;branchName&amp;gt; // create and checkout a new branch
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If you guys have other thoughts leave a comment I'll update the post base on your solutions as well.. cheers🍻&lt;/p&gt;

</description>
      <category>beginners</category>
      <category>git</category>
      <category>tutorial</category>
      <category>productivity</category>
    </item>
    <item>
      <title>Interface vs Type in Typescript</title>
      <dc:creator>Muhammad Ridho Anshory</dc:creator>
      <pubDate>Sun, 13 Feb 2022 13:17:02 +0000</pubDate>
      <link>https://dev.to/ridhoanshory/interface-vs-type-in-typescript-4ca0</link>
      <guid>https://dev.to/ridhoanshory/interface-vs-type-in-typescript-4ca0</guid>
      <description>&lt;p&gt;My personal convention, which I describe below, is this:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Always prefer interface over type.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  When to use &lt;code&gt;type&lt;/code&gt;?
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Use &lt;code&gt;type&lt;/code&gt; when defining an alias for primitive types (string, boolean, number, bigint, symbol, etc)&lt;/li&gt;
&lt;li&gt;Use &lt;code&gt;type&lt;/code&gt; when defining tuple types&lt;/li&gt;
&lt;li&gt;Use &lt;code&gt;type&lt;/code&gt; when defining function types&lt;/li&gt;
&lt;li&gt;Use &lt;code&gt;type&lt;/code&gt; when defining a union&lt;/li&gt;
&lt;li&gt;Use &lt;code&gt;type&lt;/code&gt; when trying to overload functions in object types via composition&lt;/li&gt;
&lt;li&gt;Use &lt;code&gt;type&lt;/code&gt; when needing to take advantage of mapped types&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Additions:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Generic Transformations&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Use the &lt;code&gt;type&lt;/code&gt; when you are transforming multiple types into a single generic type.&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 Nullable&amp;lt;T&amp;gt; = T | null | undefined
type NonNull&amp;lt;T&amp;gt; = T extends (null | undefined) ? never : T

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

&lt;/div&gt;






&lt;p&gt;&lt;strong&gt;Type Aliasing&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;We can use the &lt;code&gt;type&lt;/code&gt; for creating the aliases for long or complicated types that are hard to read as well as inconvenient to type again and again.&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 Primitive = number | string | boolean | null | undefined

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

&lt;/div&gt;



&lt;p&gt;Creating an alias like this makes the code more concise and readable.&lt;/p&gt;




&lt;p&gt;&lt;strong&gt;Type Capturing&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Use the &lt;code&gt;type&lt;/code&gt; to capture the type of an object when the type is unknown.&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;const orange = { color: "Orange", vitamin: "C"}
type Fruit = typeof orange
let apple: Fruit

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

&lt;/div&gt;



&lt;p&gt;Here, we get the unknown type of &lt;code&gt;orange&lt;/code&gt;, call it a &lt;code&gt;Fruit&lt;/code&gt; and then use the &lt;code&gt;Fruit&lt;/code&gt; to create a new type-safe object &lt;code&gt;apple&lt;/code&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  When to use &lt;code&gt;interface&lt;/code&gt;?
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Use &lt;code&gt;interface&lt;/code&gt; for all object types where using &lt;code&gt;type&lt;/code&gt; is not required (see above)&lt;/li&gt;
&lt;li&gt;Use &lt;code&gt;interface&lt;/code&gt; when you want to take advantage of declaration merging.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Additions:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Polymorphism&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;An &lt;code&gt;interface&lt;/code&gt; is a contract to implement a shape of the data. Use the interface to make it clear that it is intended to be implemented and used as a contract about how the object will be used.&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;interface Bird {
    size: number
    fly(): void
    sleep(): void
}

class Hummingbird implements Bird { ... }
class Bellbird implements Bird { ... }

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

&lt;/div&gt;



&lt;p&gt;Though you can use the &lt;code&gt;type&lt;/code&gt; to achieve this, the Typescript is seen more as an object oriented language and the &lt;code&gt;interface&lt;/code&gt; has a special place in object oriented languages. It's easier to read the code with &lt;code&gt;interface&lt;/code&gt; when you are working in a team environment or contributing to the open source community. It's easy on the new programmers coming from the other object oriented languages too.&lt;/p&gt;

&lt;p&gt;The official Typescript &lt;a href="https://www.typescriptlang.org/docs/handbook/advanced-types.html#interfaces-vs-type-aliases"&gt;documentation&lt;/a&gt; also says:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;... we recommend using an interface over a type alias when possible.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;em&gt;This also suggests that the &lt;code&gt;type&lt;/code&gt; is more intended for creating type aliases than creating the types themselves.&lt;/em&gt;&lt;/p&gt;




&lt;p&gt;&lt;strong&gt;Declaration Merging&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;You can use the declaration merging feature of the &lt;code&gt;interface&lt;/code&gt; for adding new properties and methods to an already declared &lt;code&gt;interface&lt;/code&gt;. This is useful for the ambient type declarations of third party libraries. When some declarations are missing for a third party library, you can declare the interface again with the same name and add new properties and methods.&lt;/p&gt;

&lt;p&gt;Example:&lt;/p&gt;

&lt;p&gt;We can extend the above &lt;code&gt;Bird&lt;/code&gt; interface to include new declarations.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;interface Bird {
    color: string
    eat(): void
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;p&gt;That's it! It's easier to remember when to use what than getting lost in subtle differences between the two.&lt;/p&gt;

&lt;p&gt;PS: According to &lt;a href="https://www.typescriptlang.org/docs/handbook/2/everyday-types.html#differences-between-type-aliases-and-interfaces"&gt;TypeScript handbook&lt;/a&gt; the answer is:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Almost all features of an interface are available in type.The key distinction is that a type cannot be re-opened to add new properties vs an interface which is always extendable.&lt;/p&gt;
&lt;/blockquote&gt;

</description>
      <category>typescript</category>
      <category>react</category>
      <category>webdev</category>
      <category>beginners</category>
    </item>
    <item>
      <title>UI Components: How to make Outline Gradient Button with Transparent Background🤷‍♂️</title>
      <dc:creator>Muhammad Ridho Anshory</dc:creator>
      <pubDate>Thu, 10 Feb 2022 12:57:35 +0000</pubDate>
      <link>https://dev.to/ridhoanshory/ui-components-how-to-make-outlined-gradient-button-with-transparent-background-ca0</link>
      <guid>https://dev.to/ridhoanshory/ui-components-how-to-make-outlined-gradient-button-with-transparent-background-ca0</guid>
      <description>&lt;p&gt;During developing 🧑‍💻 website’s at my workplace, I was facing some difficulty when it comes to outlining some div or button with gradient color. After hours crawling on google, I find the solutions.. &lt;/p&gt;

&lt;p&gt;I wanted to share my thought about it and maybe you guys have another different approach to really &lt;strong&gt;save our time ⏰&lt;/strong&gt; solving the issues.&lt;/p&gt;

&lt;h2&gt;
  
  
  Goal🎯
&lt;/h2&gt;

&lt;p&gt;So, on this article the goal 🎯 was making an &lt;strong&gt;Outlined Gradient Button with Transparent Background aka with opacity&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.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%2Fz9cot4lmhhtmrabu5hp7.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.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%2Fz9cot4lmhhtmrabu5hp7.png" alt="OutlinedGradientButton"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;here’s the spell 🧙‍♂️ what is it look like in CodePen ✍️&lt;/p&gt;

&lt;p&gt;&lt;iframe height="600" src="https://codepen.io/ridhoanshory/embed/eYeWdYy?height=600&amp;amp;default-tab=result&amp;amp;embed-version=2"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;p&gt;If you guys have another thoughts leave a comment I'll update the post base on your solutions as well.. cheers🍻&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>beginners</category>
      <category>tutorial</category>
      <category>css</category>
    </item>
    <item>
      <title>Next.JS + MUI v5 + TypeScript + Scss + Storybook Starter 📕</title>
      <dc:creator>Muhammad Ridho Anshory</dc:creator>
      <pubDate>Thu, 13 Jan 2022 13:26:29 +0000</pubDate>
      <link>https://dev.to/ridhoanshory/nextjs-mui-v5-typescript-scss-storybook-starter-4370</link>
      <guid>https://dev.to/ridhoanshory/nextjs-mui-v5-typescript-scss-storybook-starter-4370</guid>
      <description>&lt;p&gt;Lately, I was building a Next.js, MUI v5, TypeScript, Scss and Storybook for projects. I wanted to have a modern starter repository to speed up my development. A new boiler plate for Next.js with type checking (TypeScript), configured linter (ESlint), configured code formatter (Prettier), Sass / Scss for CSS framework with Material UI v5 theming, also Storybook to build streamlines UI development, testing, and documentation.&lt;/p&gt;

&lt;p&gt;You can check a live demo at this url : &lt;a href="https://nextjs-ts-mui5-scss-storybook-starter.vercel.app/"&gt;click me!&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;You can also check the source code 📕 on GitHub: &lt;a href="https://github.com/RidhoAnshory/nextjs-ts-mui5-scss-storybook-starter"&gt;nextjs-ts-mui5-scss-storybook-starter&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Here is the list of major feature:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;✍️ code snippet for react and next.js that I personally use&lt;/li&gt;
&lt;li&gt;🎨 pre-configured Sass, MUI v5, and Storybook. You just need to focus on building your components&lt;/li&gt;
&lt;li&gt;⌨️ Type checking with TypeScript&lt;/li&gt;
&lt;li&gt;✏️ Linter with Eslint and Prettier also simple-import&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Please leave a star ⭐ or some comment if there's a issue! Thanks ✌️&lt;/p&gt;

</description>
      <category>typescript</category>
      <category>nextjs</category>
      <category>javascript</category>
      <category>productivity</category>
    </item>
    <item>
      <title>Hi my new post</title>
      <dc:creator>Muhammad Ridho Anshory</dc:creator>
      <pubDate>Sun, 02 Jan 2022 09:18:47 +0000</pubDate>
      <link>https://dev.to/ridhoanshory/hi-my-new-post-51g0</link>
      <guid>https://dev.to/ridhoanshory/hi-my-new-post-51g0</guid>
      <description>&lt;p&gt;How to write hello World&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>webdev</category>
      <category>beginners</category>
    </item>
  </channel>
</rss>
