<?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: Sam Piggott</title>
    <description>The latest articles on DEV Community by Sam Piggott (@sam_piggott).</description>
    <link>https://dev.to/sam_piggott</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%2F347444%2Fe9c519c0-f28c-40d9-9ed2-5888ad65a5c4.jpg</url>
      <title>DEV Community: Sam Piggott</title>
      <link>https://dev.to/sam_piggott</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/sam_piggott"/>
    <language>en</language>
    <item>
      <title>Using Framer Motion &amp; React to build TikTok's record button</title>
      <dc:creator>Sam Piggott</dc:creator>
      <pubDate>Mon, 26 Apr 2021 09:29:05 +0000</pubDate>
      <link>https://dev.to/sam_piggott/animating-the-tiktok-record-button-in-react-framer-motion-4he9</link>
      <guid>https://dev.to/sam_piggott/animating-the-tiktok-record-button-in-react-framer-motion-4he9</guid>
      <description>&lt;p&gt;&lt;iframe width="710" height="399" src="https://www.youtube.com/embed/UnTBtDDyN2M"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

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

&lt;p&gt;The TikTok record button is a deceivingly complicated UI element with some interesting moving parts, so I thought it would be perfect for a tutorial. In the guide above, we'll build a fully animated record button using nothing but React, Framer Motion (a fantastic animation library), and TypeScript.&lt;/p&gt;

&lt;h2&gt;
  
  
  Project Files
&lt;/h2&gt;

&lt;p&gt;All the project files are available to download and use yourself over on my website, &lt;a href="https://codesnap.io/course/react-bites/tiktok-record-button"&gt;CodeSnap.io.&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Demo
&lt;/h2&gt;

&lt;p&gt;&lt;iframe src="https://codesandbox.io/embed/agitated-shockley-cdzuy"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;h2&gt;
  
  
  Thanks!
&lt;/h2&gt;

&lt;p&gt;Thanks for watching - any and all feedback is greatly appreciated, and please share it around if you think it'll be useful to anybody else. If you're interested in learning more, I've got loads more video and written content over on my website, &lt;a href="https://codesnap.io"&gt;CodeSnap.io.&lt;/a&gt;.&lt;/p&gt;

</description>
      <category>react</category>
      <category>javascript</category>
      <category>tutorial</category>
      <category>webdev</category>
    </item>
    <item>
      <title>Building TikTok's record button using Framer Motion &amp; React</title>
      <dc:creator>Sam Piggott</dc:creator>
      <pubDate>Wed, 21 Apr 2021 11:51:44 +0000</pubDate>
      <link>https://dev.to/sam_piggott/building-tiktok-s-record-button-using-framer-motion-react-5e4p</link>
      <guid>https://dev.to/sam_piggott/building-tiktok-s-record-button-using-framer-motion-react-5e4p</guid>
      <description>&lt;p&gt;&lt;iframe width="710" height="399" src="https://www.youtube.com/embed/UnTBtDDyN2M"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

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

&lt;p&gt;The TikTok record button is a deceivingly complicated UI element with some interesting moving parts, so I thought it would be perfect for a tutorial. In the guide above, we'll build a fully animated record button using nothing but React, Framer Motion (a fantastic animation library), and TypeScript.&lt;/p&gt;

&lt;h2&gt;
  
  
  Project Files
&lt;/h2&gt;

&lt;p&gt;All the project files are available to download and use yourself over on my website, &lt;a href="https://codesnap.io/course/react-bites/tiktok-record-button"&gt;CodeSnap.io.&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Demo
&lt;/h2&gt;

&lt;p&gt;&lt;iframe src="https://codesandbox.io/embed/agitated-shockley-cdzuy"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;h2&gt;
  
  
  Thanks!
&lt;/h2&gt;

&lt;p&gt;Thanks for watching - any and all feedback is greatly appreciated, and please share it around if you think it'll be useful to anybody else. If you're interested in learning more, I've got loads more video and written content over on my website, &lt;a href="https://codesnap.io"&gt;CodeSnap.io.&lt;/a&gt;.&lt;/p&gt;

</description>
    </item>
    <item>
      <title>Using Framer Motion to make page transitions in React</title>
      <dc:creator>Sam Piggott</dc:creator>
      <pubDate>Wed, 27 Jan 2021 13:10:23 +0000</pubDate>
      <link>https://dev.to/sam_piggott/using-framer-motion-to-make-page-transitions-in-react-5ma</link>
      <guid>https://dev.to/sam_piggott/using-framer-motion-to-make-page-transitions-in-react-5ma</guid>
      <description>&lt;p&gt;In this short tutorial, we'll be learning how we can use the &lt;code&gt;AnimatePresence&lt;/code&gt; component provided by Framer Motion to create our very own page transitions when navigating between pages in React!&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%2Fi%2Fel44fn3e1jk9aczsva18.gif" 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%2Fi%2Fel44fn3e1jk9aczsva18.gif" alt="Animation Example"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;We'll be using React Router for this example - but this same principle should work for other router implementations, too (have tested with the &lt;strong&gt;Next.js&lt;/strong&gt; router and it worked with no issues!)&lt;/p&gt;

&lt;h2&gt;
  
  
  Watch the Video Tutorial:
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://codesnap.io/course/react-bites/framer-motion-page-transitions" rel="noopener noreferrer"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fi.imgur.com%2FBxK9xNo.png" alt="Video Tutorial"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;You can also download the source code from the link above, too!&lt;/p&gt;

&lt;h3&gt;
  
  
  Installing the required packages
&lt;/h3&gt;

&lt;p&gt;First of all, let's install the required packages into our React project. We'll need React Router for navigation, and Framer Motion for the transition behaviour.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;yarn add react-router-dom framer-motion
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Adding a BrowserRouter to our app
&lt;/h3&gt;

&lt;p&gt;Next, in the top-level component where &lt;code&gt;ReactDOM.Render&lt;/code&gt; is called (for me, &lt;code&gt;index.tsx&lt;/code&gt;), we'll want to wrap our app's container in an instance of &lt;code&gt;&amp;lt;Router&amp;gt;&lt;/code&gt; from &lt;code&gt;react-router&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;First, we'll add the necessary imports to &lt;code&gt;index.tsx&lt;/code&gt;...&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;BrowserRouter&lt;/span&gt; &lt;span class="k"&gt;as&lt;/span&gt; &lt;span class="nx"&gt;Router&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;react-router-dom&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;Then, we'll wrap our top-level component in an instance of this router.&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;ReactDOM&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;render&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
  &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;React&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;StrictMode&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="nc"&gt;Router&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;Adding&lt;/span&gt; &lt;span class="na"&gt;this&lt;/span&gt;&lt;span class="err"&gt;...&lt;/span&gt;
      &lt;span class="err"&gt;&amp;lt;&lt;/span&gt;&lt;span class="na"&gt;App&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="nc"&gt;Router&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="err"&gt;...&lt;/span&gt;&lt;span class="na"&gt;and&lt;/span&gt; &lt;span class="na"&gt;this&lt;/span&gt;&lt;span class="err"&gt;!&lt;/span&gt;
  &lt;span class="err"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="na"&gt;React&lt;/span&gt;&lt;span class="err"&gt;.&lt;/span&gt;&lt;span class="na"&gt;StrictMode&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;,
  document.getElementById('root')
);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Building a simple switch
&lt;/h3&gt;

&lt;p&gt;Next, we'll need to make some changes to the component immediately beneath the top-level component (in our example, the &lt;code&gt;App&lt;/code&gt; component).&lt;/p&gt;

&lt;p&gt;Inside the &lt;code&gt;App&lt;/code&gt; component, we'll set up a basic routing system for our app. In this example, we're only going to be navigating between two simple pages - so we just need a &lt;code&gt;&amp;lt;Switch&amp;gt;&lt;/code&gt; and two &lt;code&gt;&amp;lt;Route&amp;gt;&lt;/code&gt; components to get us going.&lt;/p&gt;

&lt;p&gt;So let's import those in our &lt;code&gt;App.tsx&lt;/code&gt; file first...&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;Switch&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;Route&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;react-router-dom&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;Then below, we'll return our simple switch from our &lt;code&gt;App&lt;/code&gt; component. For clarity, &lt;code&gt;Page1&lt;/code&gt; and &lt;code&gt;Page2&lt;/code&gt; components can be any valid React component.&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;const&lt;/span&gt; &lt;span class="nx"&gt;App&lt;/span&gt; &lt;span class="o"&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="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;return &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;Switch&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="nc"&gt;Route&lt;/span&gt; &lt;span class="na"&gt;path&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"/page1"&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="nc"&gt;Page1&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="nc"&gt;Route&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="nc"&gt;Route&lt;/span&gt; &lt;span class="na"&gt;path&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"/page2"&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="nc"&gt;Page2&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="nc"&gt;Route&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="nc"&gt;Switch&lt;/span&gt;&lt;span class="p"&gt;&amp;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;h3&gt;
  
  
  Adding AnimatePresence from Framer Motion
&lt;/h3&gt;

&lt;p&gt;Now, it's time to add the animation! First, we'll wrap our &lt;code&gt;&amp;lt;Switch&amp;gt;&lt;/code&gt; in the &lt;code&gt;&amp;lt;AnimatePresence&amp;gt;&lt;/code&gt; component from Framer Motion. Let's import that first...&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;AnimatePresence&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;framer-motion&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;Then, let's wrap our app in that new component.&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;const&lt;/span&gt; &lt;span class="nx"&gt;App&lt;/span&gt; &lt;span class="o"&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="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;return &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;AnimatePresence&lt;/span&gt; &lt;span class="na"&gt;exitBeforeEnter&lt;/span&gt; &lt;span class="na"&gt;initial&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="kc"&gt;false&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="nc"&gt;Switch&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="nc"&gt;Route&lt;/span&gt; &lt;span class="na"&gt;path&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"/page1"&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="nc"&gt;Page1&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="nc"&gt;Route&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="nc"&gt;Route&lt;/span&gt; &lt;span class="na"&gt;path&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"/page2"&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="nc"&gt;Page2&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="nc"&gt;Route&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="nc"&gt;Switch&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="nc"&gt;AnimatePresence&lt;/span&gt;&lt;span class="p"&gt;&amp;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;Transitions with &lt;code&gt;AnimatePresence&lt;/code&gt; only work when the child immediately below the &lt;code&gt;AnimatePresence&lt;/code&gt; component changes. In that case, that's our &lt;code&gt;Switch&lt;/code&gt; component. We'll need to add some props to help &lt;code&gt;AnimatePresence&lt;/code&gt; recognise when that change has occurred.&lt;/p&gt;

&lt;p&gt;Once again, in &lt;code&gt;App.tsx&lt;/code&gt;, we're going to import the &lt;code&gt;useLocation&lt;/code&gt; hook from &lt;code&gt;react-router&lt;/code&gt;.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;useLocation&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;react-router-dom&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;And now, let's add the &lt;code&gt;location&lt;/code&gt; and &lt;code&gt;key&lt;/code&gt; props to our &lt;code&gt;Switch&lt;/code&gt;.&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;const&lt;/span&gt; &lt;span class="nx"&gt;App&lt;/span&gt; &lt;span class="o"&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="p"&gt;{&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;location&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;useLocation&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
  &lt;span class="k"&gt;return &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;AnimatePresence&lt;/span&gt; &lt;span class="na"&gt;exitBeforeEnter&lt;/span&gt; &lt;span class="na"&gt;initial&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="kc"&gt;false&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="nc"&gt;Switch&lt;/span&gt; &lt;span class="na"&gt;location&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;location&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt; &lt;span class="na"&gt;key&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;location&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;pathname&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="nc"&gt;Route&lt;/span&gt; &lt;span class="na"&gt;path&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"/page1"&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="nc"&gt;Page1&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="nc"&gt;Route&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="nc"&gt;Route&lt;/span&gt; &lt;span class="na"&gt;path&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"/page2"&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="nc"&gt;Page2&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="nc"&gt;Route&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="nc"&gt;Switch&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="nc"&gt;AnimatePresence&lt;/span&gt;&lt;span class="p"&gt;&amp;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;h3&gt;
  
  
  Adding the transition effect parameters to our page components
&lt;/h3&gt;

&lt;p&gt;Great news - we're done with our App component. Now, let's add some animations to our pages, and we should be ready to go!&lt;/p&gt;

&lt;p&gt;Here's the &lt;code&gt;Page1&lt;/code&gt; component I'm working with. It's super simple - just a simple &lt;code&gt;div&lt;/code&gt; with some styles, and a &lt;code&gt;Link&lt;/code&gt; to our other page in the app.&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;const&lt;/span&gt; &lt;span class="nx"&gt;Page1&lt;/span&gt; &lt;span class="o"&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="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;return &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nt"&gt;div&lt;/span&gt; &lt;span class="na"&gt;style&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="si"&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;styles&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;page&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;...&lt;/span&gt;&lt;span class="nx"&gt;styles&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;page1&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;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="na"&gt;style&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;styles&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;copy&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;This is page 1&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="nc"&gt;Link&lt;/span&gt; &lt;span class="na"&gt;style&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="si"&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;styles&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;copy&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;...&lt;/span&gt;&lt;span class="nx"&gt;styles&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;link&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt; &lt;span class="na"&gt;to&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"/page2"&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
        Go to Page 2
      &lt;span class="p"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nc"&gt;Link&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;div&lt;/span&gt;&lt;span class="p"&gt;&amp;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;To trigger an animation when this &lt;code&gt;Page1&lt;/code&gt; component is mounted, we'll need to wrap it in a special component called &lt;code&gt;motion.div&lt;/code&gt; which is provided by Framer Motion. So, let's import that...&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;motion&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;framer-motion&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;Now, we'll wrap our &lt;code&gt;Page1&lt;/code&gt; component in our new &lt;code&gt;motion.div&lt;/code&gt; component, and provide some props to perform the animation when it's mounted.&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;const&lt;/span&gt; &lt;span class="nx"&gt;Page1&lt;/span&gt; &lt;span class="o"&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="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;return &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nt"&gt;motion&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nt"&gt;div&lt;/span&gt;
      &lt;span class="na"&gt;initial&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="na"&gt;scaleY&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="si"&gt;}&lt;/span&gt;
      &lt;span class="na"&gt;animate&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="na"&gt;scaleY&lt;/span&gt;&lt;span class="p"&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="na"&gt;exit&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="na"&gt;scaleY&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="si"&gt;}&lt;/span&gt;
      &lt;span class="na"&gt;transition&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="na"&gt;duration&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mf"&gt;0.5&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;gt;&lt;/span&gt;
      &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nt"&gt;div&lt;/span&gt; &lt;span class="na"&gt;style&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="si"&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;styles&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;page&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;...&lt;/span&gt;&lt;span class="nx"&gt;styles&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;page1&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;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="na"&gt;style&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;styles&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;copy&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;This is page 1&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="nc"&gt;Link&lt;/span&gt; &lt;span class="na"&gt;style&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="si"&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;styles&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;copy&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;...&lt;/span&gt;&lt;span class="nx"&gt;styles&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;link&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt; &lt;span class="na"&gt;to&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"/page2"&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
          Go to Page 2
        &lt;span class="p"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nc"&gt;Link&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;div&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;motion&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nt"&gt;div&lt;/span&gt;&lt;span class="p"&gt;&amp;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;As you can see, we've added three new props to our &lt;code&gt;motion.div&lt;/code&gt; component here, too.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;initial&lt;/strong&gt; - This is the style of the component at the &lt;strong&gt;beginning&lt;/strong&gt; of the animation when it is &lt;strong&gt;animating in&lt;/strong&gt;.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;animate&lt;/strong&gt; - This is the style of the component at the &lt;strong&gt;end&lt;/strong&gt; of the animation when it is &lt;strong&gt;animating in&lt;/strong&gt;.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;exit&lt;/strong&gt; - This is the style of the component at the &lt;strong&gt;end&lt;/strong&gt; of the animation when it is &lt;strong&gt;animating out&lt;/strong&gt;.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;transition&lt;/strong&gt; - Transition configuration. Here, we're specifying how long we want the duration to last for (in our case, 0.5 seconds).&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;With those props in place, we can expect the following behaviour:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;When the prop is first mounted, it is invisible (&lt;code&gt;scaleY: 0&lt;/code&gt;)&lt;/li&gt;
&lt;li&gt;Then, it will immediately animate over 0.5 seconds to be visible (&lt;code&gt;scaleY: 1&lt;/code&gt;).&lt;/li&gt;
&lt;li&gt;When it is animating out, it will resize back down before it is removed from the DOM (&lt;code&gt;scaleY: 0&lt;/code&gt;).&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Finally, the only other thing we need to do is wrap our other page components that we wish to animate using the same method.&lt;/p&gt;

&lt;p&gt;I'm animating between two pages (&lt;code&gt;Page1&lt;/code&gt; and &lt;code&gt;Page2&lt;/code&gt; in this example), so I'll need to wrap &lt;code&gt;Page2&lt;/code&gt; in a &lt;code&gt;motion.div&lt;/code&gt; tag, too.&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;const&lt;/span&gt; &lt;span class="nx"&gt;Page2&lt;/span&gt; &lt;span class="o"&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="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;return &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nt"&gt;motion&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nt"&gt;div&lt;/span&gt;
      &lt;span class="na"&gt;initial&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="na"&gt;scaleY&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="si"&gt;}&lt;/span&gt;
      &lt;span class="na"&gt;animate&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="na"&gt;scaleY&lt;/span&gt;&lt;span class="p"&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="na"&gt;exit&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="na"&gt;scaleY&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="si"&gt;}&lt;/span&gt;
      &lt;span class="na"&gt;transition&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="na"&gt;duration&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mf"&gt;0.5&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;gt;&lt;/span&gt;
      &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nt"&gt;div&lt;/span&gt; &lt;span class="na"&gt;style&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="si"&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;styles&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;page&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;...&lt;/span&gt;&lt;span class="nx"&gt;styles&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;page2&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;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="na"&gt;style&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;styles&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;copy&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;This is page 2&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="nc"&gt;Link&lt;/span&gt; &lt;span class="na"&gt;style&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="si"&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;styles&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;copy&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;...&lt;/span&gt;&lt;span class="nx"&gt;styles&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;link&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt; &lt;span class="na"&gt;to&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"/page1"&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
          Go to Page 1
        &lt;span class="p"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nc"&gt;Link&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;div&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;motion&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nt"&gt;div&lt;/span&gt;&lt;span class="p"&gt;&amp;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;h3&gt;
  
  
  And we're done!
&lt;/h3&gt;

&lt;p&gt;And with that, we are done! We have successfully set up a fancy animation when navigating between pages in React.&lt;/p&gt;

&lt;p&gt;You should now also have all the knowledge you need to customise your transition styles, too. Each page can also have different transition styles - the sky's the limit!&lt;/p&gt;

&lt;h3&gt;
  
  
  CodeSnap
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://codesnap.io" rel="noopener noreferrer"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fi.imgur.com%2FmwdAzpU.png" alt="CodeSnap Preview"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;If you enjoyed this course, I'm uploading tutorial videos, courses, articles and plenty more. If you'd like to see more of this content, please consider signing up for the mailing list over on &lt;a href="https://codesnap.io" rel="noopener noreferrer"&gt;&lt;strong&gt;CodeSnap.io&lt;/strong&gt;&lt;/a&gt;. It encourages me to make more videos and articles just like this one 🙏&lt;/p&gt;

&lt;p&gt;Thanks for reading!&lt;/p&gt;

</description>
      <category>react</category>
      <category>javascript</category>
      <category>webdev</category>
      <category>tutorial</category>
    </item>
    <item>
      <title>⚡️ Full TypeScript Beginner's Course [Free!]</title>
      <dc:creator>Sam Piggott</dc:creator>
      <pubDate>Sat, 23 Jan 2021 12:27:02 +0000</pubDate>
      <link>https://dev.to/sam_piggott/full-typescript-beginner-s-course-free-22mg</link>
      <guid>https://dev.to/sam_piggott/full-typescript-beginner-s-course-free-22mg</guid>
      <description>&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%2Fi.imgur.com%2FlpjigdW.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%2Fi.imgur.com%2FlpjigdW.png" alt="CodeSnap Intro"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Over lockdown, I wrote, shot and edited a full TypeScript course for my website, &lt;a href="https://codesnap.io" rel="noopener noreferrer"&gt;CodeSnap&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;It's been designed for JavaScript developers who want to learn TypeScript in a way which they're already familiar with.&lt;/p&gt;

&lt;p&gt;The best thing is - it's totally free!&lt;/p&gt;

&lt;p&gt;&lt;a href="https://codesnap.io/course/introduction-to-typescript" rel="noopener noreferrer"&gt;&lt;strong&gt;Watch the full course here!&lt;/strong&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
   Details
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;⏰ Full 2 hour course&lt;/li&gt;
&lt;li&gt;✅ Everything you need to know to get started with TypeScript&lt;/li&gt;
&lt;li&gt;📹 16 videos (each around 8-10 minutes long)&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  All Chapters
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Introduction &amp;amp; Setup
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Chapter 1:&lt;/strong&gt; &lt;a href="https://codesnap.io/course/introduction-to-typescript/what-is-typescript" rel="noopener noreferrer"&gt;What is TypeScript?&lt;/a&gt;&lt;br&gt;
&lt;strong&gt;Chapter 2:&lt;/strong&gt; &lt;a href="https://codesnap.io/course/introduction-to-typescript/welcome" rel="noopener noreferrer"&gt;Welcome to the course!&lt;/a&gt;&lt;br&gt;
&lt;strong&gt;Chapter 3:&lt;/strong&gt; &lt;a href="https://codesnap.io/course/introduction-to-typescript/setting-up-project" rel="noopener noreferrer"&gt;Setting up our environment (TypeScript, ESLint and Prettier)&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Getting Started
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Chapter 4:&lt;/strong&gt; &lt;a href="https://codesnap.io/course/introduction-to-typescript/basic-types" rel="noopener noreferrer"&gt;Basic Types (strings, numbers etc)&lt;/a&gt;&lt;br&gt;
&lt;strong&gt;Chapter 5:&lt;/strong&gt; &lt;a href="https://codesnap.io/course/introduction-to-typescript/" rel="noopener noreferrer"&gt;Type Inference&lt;/a&gt;&lt;br&gt;
&lt;strong&gt;Chapter 6:&lt;/strong&gt; &lt;a href="https://codesnap.io/course/introduction-to-typescript/" rel="noopener noreferrer"&gt;Union Types&lt;/a&gt;&lt;br&gt;
&lt;strong&gt;Chapter 7:&lt;/strong&gt; &lt;a href="https://codesnap.io/course/introduction-to-typescript/" rel="noopener noreferrer"&gt;Arrays &amp;amp; Tuples&lt;/a&gt;&lt;br&gt;
&lt;strong&gt;Chapter 8:&lt;/strong&gt; &lt;a href="https://codesnap.io/course/introduction-to-typescript/" rel="noopener noreferrer"&gt;Any &amp;amp; Unknown&lt;/a&gt;&lt;br&gt;
&lt;strong&gt;Chapter 9:&lt;/strong&gt; &lt;a href="https://codesnap.io/course/introduction-to-typescript/" rel="noopener noreferrer"&gt;Undefined &amp;amp; Null&lt;/a&gt;&lt;br&gt;
&lt;strong&gt;Chapter 10:&lt;/strong&gt; &lt;a href="https://codesnap.io/course/introduction-to-typescript/" rel="noopener noreferrer"&gt;Enums&lt;/a&gt;&lt;br&gt;
&lt;strong&gt;Chapter 11:&lt;/strong&gt; &lt;a href="https://codesnap.io/course/introduction-to-typescript/" rel="noopener noreferrer"&gt;Interfaces&lt;/a&gt;&lt;br&gt;
&lt;strong&gt;Chapter 12:&lt;/strong&gt; &lt;a href="https://codesnap.io/course/introduction-to-typescript/" rel="noopener noreferrer"&gt;Functions&lt;/a&gt;&lt;br&gt;
&lt;strong&gt;Chapter 13:&lt;/strong&gt; &lt;a href="https://codesnap.io/course/introduction-to-typescript/" rel="noopener noreferrer"&gt;Literal Types&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Writing a mini project with everything we've learned
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Chapter 14:&lt;/strong&gt; &lt;a href="https://codesnap.io/course/introduction-to-typescript/" rel="noopener noreferrer"&gt;Writing an application in TypeScript - Part 1&lt;/a&gt;&lt;br&gt;
&lt;strong&gt;Chapter 15:&lt;/strong&gt; &lt;a href="https://codesnap.io/course/introduction-to-typescript/" rel="noopener noreferrer"&gt;Writing an application in TypeScript - Part 2&lt;/a&gt;&lt;br&gt;
&lt;strong&gt;Chapter 16:&lt;/strong&gt; &lt;a href="https://codesnap.io/course/introduction-to-typescript/" rel="noopener noreferrer"&gt;Writing an application in TypeScript - Part 3&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Support
&lt;/h2&gt;

&lt;p&gt;I loved making this course, but it took bloody ages to put together...!&lt;/p&gt;

&lt;p&gt;If you want to support me, and encourage me to make more videos &amp;amp; courses like this, I'd love it if &lt;a href="https://codesnap.io" rel="noopener noreferrer"&gt;you could sign up to the email list&lt;/a&gt;. It gives me a bit more guidance to see the amount of people interested in the content, and keeps me motivated to make more!&lt;/p&gt;

&lt;h2&gt;
  
  
  Thanks!
&lt;/h2&gt;

&lt;p&gt;Thanks for watching - any and all feedback is greatly appreciated, and please share it around if you think it'll be useful to anybody else.&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>typescript</category>
      <category>webdev</category>
      <category>tutorial</category>
    </item>
    <item>
      <title>Setting up TypeScript with ESLint &amp; Prettier for Visual Studio Code</title>
      <dc:creator>Sam Piggott</dc:creator>
      <pubDate>Mon, 14 Dec 2020 08:42:24 +0000</pubDate>
      <link>https://dev.to/sam_piggott/setting-up-typescript-with-eslint-prettier-for-visual-studio-code-1e3h</link>
      <guid>https://dev.to/sam_piggott/setting-up-typescript-with-eslint-prettier-for-visual-studio-code-1e3h</guid>
      <description>&lt;p&gt;Okay, if you've stumbled on this article, chances are you probably want this information as quick and easy as possible. &lt;/p&gt;

&lt;p&gt;I'll keep things as short as I can, but we will be walking through everything step-by-step.&lt;/p&gt;

&lt;p&gt;Here's a quick introduction on what everything is that we'll be setting up today:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;TypeScript 4&lt;/strong&gt; is an evolution of JavaScript which brings strict typing (and much more!) to the JavaScript language. I've got a whole article introducing TypeScript &lt;a href="https://dev.to/sam_piggott/getting-started-with-typescript-as-a-javascript-developer-4b3l"&gt;right here&lt;/a&gt; if you're interested in learning more.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;ESLint&lt;/strong&gt; is a tool which scans your code for errors in your codebase, and offers fixes as you go (also known as "linting").&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Prettier&lt;/strong&gt; is a code formatter which formats your code to make it look prettier (hence the name!)&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Prefer video?
&lt;/h2&gt;

&lt;p&gt;Before we get started - I've recorded a video available with all of the following steps in it:&lt;/p&gt;

&lt;p&gt;&lt;iframe width="710" height="399" src="https://www.youtube.com/embed/q5rA2cNqm-8"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;p&gt;The video is part of a completely free &lt;strong&gt;16 part series&lt;/strong&gt; available to watch &lt;strong&gt;for free&lt;/strong&gt; over on my YouTube channel. &lt;a href="https://www.youtube.com/watch?v=vugSEGpPsEo&amp;amp;list=PL7siRj7spTbBfiNQ1kBVuytL8-I8DZWZq" rel="noopener noreferrer"&gt;Click here to get the full course!&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Hold up - why is this guide so long?!
&lt;/h2&gt;

&lt;p&gt;There are other ways to get up and running with these tools quickly (such as running an &lt;code&gt;npx&lt;/code&gt; command, pre-installing everything). &lt;/p&gt;

&lt;p&gt;Here's why I think you should follow this (longer) guide instead:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Full transparency as to what you're installing, step-by-step (no unwanted libraries or bloat)&lt;/li&gt;
&lt;li&gt;Installing everything step-by-step (with explanations) makes it easier to debug particular bugs if any of these tools fail&lt;/li&gt;
&lt;li&gt;A greater understanding of the individual tools will make it easier to extend or change any of the tools' behaviour later!&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Just want the code?
&lt;/h2&gt;

&lt;p&gt;With all of that said - if you'd rather just get up and running quickly, I've written a git repo with everything described in this guide. It's available &lt;a href="https://github.com/Sarghm/typescript-eslint-prettier-template" rel="noopener noreferrer"&gt;right here.&lt;/a&gt; &lt;/p&gt;

&lt;p&gt;If it's useful, I'd appreciate a star! ✨&lt;/p&gt;

&lt;p&gt;Still here? Alright! On with the show!&lt;/p&gt;

&lt;h2&gt;
  
  
  Installing TypeScript
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Step 1:&lt;/strong&gt; We'll start by creating a new folder to use as a root for our project. In your command line, enter the following command (replacing &lt;code&gt;my-new-project&lt;/code&gt; with your project's name):&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="nb"&gt;mkdir &lt;/span&gt;my-new-project
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Step 2:&lt;/strong&gt; Next, we need to get our project set up using &lt;strong&gt;Yarn&lt;/strong&gt;. To do this, we'll need to enter the folder we've just created and initialise our project.&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="nb"&gt;cd &lt;/span&gt;my-new-project
yarn init
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This should give us an interactive series of steps where we can enter all the relevant information for our project in.&lt;/p&gt;

&lt;p&gt;Enter values for all of these if you have anything specific, or just press Enter to use the defaults for each (shown in parentheses after each question).&lt;/p&gt;

&lt;p&gt;The only one to pay attention to is the &lt;strong&gt;entry point&lt;/strong&gt; - make sure you enter &lt;code&gt;./build/index.js&lt;/code&gt; rather than just &lt;code&gt;index.js&lt;/code&gt;. I'll highlight why later in the article.&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%2Fi.imgur.com%2FeuJIg30.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%2Fi.imgur.com%2FeuJIg30.png" alt="Yarn Init interactive steps"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 3:&lt;/strong&gt; Okay, now that we've initialised our project, let's go ahead and install TypeScript into our project. &lt;/p&gt;

&lt;p&gt;Using the same command line (still navigated to the &lt;code&gt;my-new-project&lt;/code&gt; directory), enter the following command:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;yarn add typescript &lt;span class="nt"&gt;--dev&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This will add TypeScript to our &lt;code&gt;devDependencies&lt;/code&gt;. For more information on the difference between &lt;code&gt;dependencies&lt;/code&gt; and &lt;code&gt;devDependencies&lt;/code&gt;, there's an article you can check out &lt;a href="https://medium.com/@dylanavery720/npmmmm-1-dev-dependencies-dependencies-8931c2583b0c#:~:text=The%20difference%20between%20these%20two,an%20npm%20install%20%2D%2Dsave." rel="noopener noreferrer"&gt;right here&lt;/a&gt;. &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 4:&lt;/strong&gt; After that's installed, we'll need to create ourselves a configuration file for TypeScript to use. &lt;/p&gt;

&lt;p&gt;To create that, enter the following command:&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="nb"&gt;touch&lt;/span&gt; ./tsconfig.json
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Step 5:&lt;/strong&gt; Next, we'll create a folder to store our TypeScript files in, and create an &lt;code&gt;index.ts&lt;/code&gt; file to get started. Back in your command line, enter the following:&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="nb"&gt;mkdir&lt;/span&gt; ./src
&lt;span class="nb"&gt;touch&lt;/span&gt; ./src/index.ts
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Great - now we've created a folder in our project's directory called &lt;code&gt;src&lt;/code&gt;, and created a single file called &lt;code&gt;index.ts&lt;/code&gt; inside.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 6:&lt;/strong&gt; Next, you'll want to open up the &lt;code&gt;tsconfig.json&lt;/code&gt; file that we just created, using VSCode. &lt;/p&gt;

&lt;p&gt;We're going to set our TypeScript's configuration up with the simplest settings possible, with the idea being that you can add to and extend this. Feel free to copy and paste the following configuration (feel free to remove the comments - they're not required, more just to let you know what each line does!)&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;compilerOptions&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;rootDir&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;./src&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="c1"&gt;// The entry point for all of our TypeScript files (make sure all .ts files are stored in a subdirectory of this!)&lt;/span&gt;
        &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;outDir&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;./build&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="c1"&gt;// The directory which we'll be exporting our compiled JavaScript files to&lt;/span&gt;
        &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;lib&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;ESNext&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;DOM&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt; &lt;span class="c1"&gt;// The libraries we wish to use in TS (ESNext being the latest version of JavaScript, and DOM being JavaScript DOM libraries - like console.log)&lt;/span&gt;
        &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;strict&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt; &lt;span class="c1"&gt;// Stipulating we want strict mode on. I personally would recommend this to get the most out of TS - another great article on this here: https://dev.to/briwa/how-strict-is-typescript-s-strict-mode-311a&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;&lt;strong&gt;Note:&lt;/strong&gt; If you're planning on setting this project up with React later down the line, there's a React-specific barebones &lt;code&gt;tsconfig.json&lt;/code&gt; you can refer to &lt;a href="https://gist.github.com/Sarghm/07140fcb4f835571af51b6f977a5e410" rel="noopener noreferrer"&gt;here&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;For more information on &lt;code&gt;tsconfig.json&lt;/code&gt; and all of the possible parameters you can use during setup, there's more information on the &lt;a href="https://www.typescriptlang.org/tsconfig" rel="noopener noreferrer"&gt;official TypeScript handbook.&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 7:&lt;/strong&gt; Finally, open up the &lt;strong&gt;root folder&lt;/strong&gt; (not just a single file!) - in VSCode.&lt;/p&gt;

&lt;p&gt;You should now be able to write TypeScript inside of your &lt;code&gt;index.ts&lt;/code&gt; file! Just make sure you create all your &lt;code&gt;.ts&lt;/code&gt; files inside of the &lt;code&gt;src&lt;/code&gt; folder (or a sub-directory inside &lt;code&gt;src&lt;/code&gt;) to ensure the compiler catches everything.&lt;/p&gt;

&lt;p&gt;To build your TypeScript into JavaScript files, simply run the following command from the root directory:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;yarn tsc &lt;span class="nt"&gt;-p&lt;/span&gt; ./tsconfig.json
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  ESLint
&lt;/h2&gt;

&lt;p&gt;Alright, let's get our codebase linted with ESLint!&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 1:&lt;/strong&gt; First, we'll want to install the relevant ESLint plugin for VSCode. Simply search for &lt;strong&gt;ESLint&lt;/strong&gt; in the Extensions bar on the left side of the screen, then hit &lt;strong&gt;Install&lt;/strong&gt; to install it.&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%2Fi.imgur.com%2FcBc3Dvc.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%2Fi.imgur.com%2FcBc3Dvc.png" alt="Installing ESLint in Visual Studio Code"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 2:&lt;/strong&gt; Open up your command line once again, and navigate to your project's root directory. From there, we want to install all the required libraries to get ESLint up and running.&lt;/p&gt;

&lt;p&gt;To do so, enter the following command:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;yarn add eslint @typescript-eslint/eslint-plugin @typescript-eslint/parser --dev
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This will install:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;eslint&lt;/strong&gt; - The ESLint core package&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;@typescript-eslint/eslint-plugin&lt;/strong&gt; - A plugin for ESLint to support TypeScript specifically&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;@typescript-eslint/parser&lt;/strong&gt; - Further support for ESLint to lint TypeScript source files&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Step 3:&lt;/strong&gt; Next, whilst we're still in the command line, we'll need to set up our configuration file for ESLint.&lt;/p&gt;

&lt;p&gt;To do so, enter the following command:&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="nb"&gt;touch&lt;/span&gt; .eslintrc
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;(Note the &lt;code&gt;.&lt;/code&gt; at the beginning of the &lt;code&gt;eslintrc&lt;/code&gt;. That's really important - make sure you don't miss it!)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 4:&lt;/strong&gt; To finish up the setup, we'll need to make some changes to the &lt;code&gt;.eslintrc&lt;/code&gt; file that we've just created. If you already have VSCode open, you should now be able to navigate to &lt;code&gt;.eslintrc&lt;/code&gt; in your project tree. &lt;/p&gt;

&lt;p&gt;Here's what that looks like on Visual Studio Code:&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%2Fi.imgur.com%2FyfitNxH.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%2Fi.imgur.com%2FyfitNxH.png" alt="Opening .eslintrc file up from the project tree in Visual Studio Code"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Now that &lt;code&gt;.eslintrc&lt;/code&gt; is open, update it so that it looks like the following:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight json"&gt;&lt;code&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="nl"&gt;"parser"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"@typescript-eslint/parser"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="nl"&gt;"parserOptions"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
        &lt;/span&gt;&lt;span class="nl"&gt;"ecmaVersion"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="mi"&gt;2021&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="p"&gt;},&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="nl"&gt;"extends"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="w"&gt;
        &lt;/span&gt;&lt;span class="s2"&gt;"plugin:@typescript-eslint/recommended"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This configuration applies all of the libraries that we've just installed.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 5:&lt;/strong&gt; Restart VSCode!&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 6:&lt;/strong&gt; You should now be able to observe an &lt;code&gt;ESLint&lt;/code&gt; marker in the status bar (bottom right corner of the screen).&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%2Fi.imgur.com%2FIw5jfzL.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%2Fi.imgur.com%2FIw5jfzL.png" alt="Positive state for ESLint"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;If it looks like the image above - great! You're all set!&lt;/p&gt;

&lt;p&gt;However, if it looks like this:&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%2Fi.imgur.com%2F8T2rTYm.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%2Fi.imgur.com%2F8T2rTYm.png" alt="Error state for ESLint"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;...you'll need to click it, and then grant the workspace the necessary permissions to use ESLint. After that, one last IDE restart should get you up and running!&lt;/p&gt;

&lt;h2&gt;
  
  
  Prettier
&lt;/h2&gt;

&lt;p&gt;Almost there! Let's get our environment configured to use Prettier...&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 1:&lt;/strong&gt; Once again, open up your command line, and navigate to your project's root directory. We'll be installing a few new packages to add support for Prettier...&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;yarn add prettier eslint-config-prettier eslint-plugin-prettier &lt;span class="nt"&gt;--dev&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Whilst we're in here, let's create a configuration file. No need to edit it - it just needs to exist.&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="nb"&gt;touch&lt;/span&gt; .prettierrc
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Step 2:&lt;/strong&gt; Next, let's open up our &lt;code&gt;.eslintrc&lt;/code&gt; file and add those new libraries to the &lt;code&gt;extends&lt;/code&gt; array in our configuration...&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight json"&gt;&lt;code&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="nl"&gt;"parser"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"@typescript-eslint/parser"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="nl"&gt;"parserOptions"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
        &lt;/span&gt;&lt;span class="nl"&gt;"ecmaVersion"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="mi"&gt;2021&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="p"&gt;},&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="nl"&gt;"extends"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="w"&gt;
        &lt;/span&gt;&lt;span class="s2"&gt;"plugin:@typescript-eslint/recommended"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
        &lt;/span&gt;&lt;span class="s2"&gt;"prettier/@typescript-eslint"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
        &lt;/span&gt;&lt;span class="s2"&gt;"plugin:prettier/recommended"&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;(&lt;strong&gt;Note:&lt;/strong&gt; The order in which the content of the &lt;code&gt;extends&lt;/code&gt; array is very important to ensure you don't have any trouble later on down the line!)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 3:&lt;/strong&gt; Finally - restart VSCode one last time.&lt;/p&gt;

&lt;p&gt;And that's it - feel free to breathe a sigh of relief. You've done it! You've set up a project with &lt;strong&gt;TypeScript&lt;/strong&gt;, &lt;strong&gt;ESLint&lt;/strong&gt; and &lt;strong&gt;Prettier!&lt;/strong&gt;&lt;/p&gt;

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

&lt;p&gt;It feels like a hell of a lot to do &lt;em&gt;just&lt;/em&gt; to get your environment ready, but I honestly believe that once you've gone through this process once and have an understanding as to how all the separate components come together, it really makes things a lot more straightforward in the event that any of these tools fail. Now that you've braved the storm, you should also be in a great position to customise ESLint and Prettier to your heart's content.&lt;/p&gt;

&lt;h2&gt;
  
  
  One last thing...
&lt;/h2&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%2Fi.imgur.com%2FTlmEDgZ.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%2Fi.imgur.com%2FTlmEDgZ.png" alt="CodeSnap promo image"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;I've made a &lt;strong&gt;16-part&lt;/strong&gt; TypeScript course, written specifically for JavaScript developers - and it's totally free. If you're interested, it's available to view on my &lt;a href="https://codesnap.io/course/introduction-to-typescript" rel="noopener noreferrer"&gt;website right here&lt;/a&gt;. You can also support this content by subscribing to me, or just following me on here for more TypeScript content.&lt;/p&gt;

&lt;p&gt;Thanks so much for reading!&lt;/p&gt;

</description>
      <category>typescript</category>
      <category>webdev</category>
      <category>javascript</category>
      <category>react</category>
    </item>
    <item>
      <title>Setting up TypeScript 4 with ESLint &amp; Prettier in Visual Studio Code</title>
      <dc:creator>Sam Piggott</dc:creator>
      <pubDate>Fri, 11 Dec 2020 09:06:58 +0000</pubDate>
      <link>https://dev.to/sam_piggott/setting-up-typescript-4-with-eslint-prettier-in-visual-studio-code-4e5n</link>
      <guid>https://dev.to/sam_piggott/setting-up-typescript-4-with-eslint-prettier-in-visual-studio-code-4e5n</guid>
      <description>&lt;p&gt;Okay, if you've stumbled on this article, chances are you probably want this information as quick and easy as possible. &lt;/p&gt;

&lt;p&gt;I'll keep things as short as I can, but we will be walking through everything step-by-step.&lt;/p&gt;

&lt;p&gt;Here's a quick introduction on what everything is that we'll be setting up today:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;TypeScript 4&lt;/strong&gt; is an evolution of JavaScript which brings strict typing (and much more!) to the JavaScript language. I've got a whole article introducing TypeScript &lt;a href="https://dev.to/sam_piggott/getting-started-with-typescript-as-a-javascript-developer-4b3l"&gt;right here&lt;/a&gt; if you're interested in learning more.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;ESLint&lt;/strong&gt; is a tool which scans your code for errors in your codebase, and offers fixes as you go (also known as "linting").&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Prettier&lt;/strong&gt; is a code formatter which formats your code to make it look prettier (hence the name!)&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Prefer video?
&lt;/h2&gt;

&lt;p&gt;Before we get started - I've recorded a video available with all of the following steps in it:&lt;/p&gt;

&lt;p&gt;&lt;iframe width="710" height="399" src="https://www.youtube.com/embed/q5rA2cNqm-8"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;p&gt;The video is part of a completely free &lt;strong&gt;16 part series&lt;/strong&gt; available to watch &lt;strong&gt;for free&lt;/strong&gt; over on my YouTube channel. &lt;a href="https://www.youtube.com/watch?v=vugSEGpPsEo&amp;amp;list=PL7siRj7spTbBfiNQ1kBVuytL8-I8DZWZq" rel="noopener noreferrer"&gt;Click here to get the full course!&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Hold up - why is this guide so long?!
&lt;/h2&gt;

&lt;p&gt;There are other ways to get up and running with these tools quickly (such as running an &lt;code&gt;npx&lt;/code&gt; command, pre-installing everything). &lt;/p&gt;

&lt;p&gt;Here's why I think you should follow this (longer) guide instead:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Full transparency as to what you're installing, step-by-step (no unwanted libraries or bloat)&lt;/li&gt;
&lt;li&gt;Installing everything step-by-step (with explanations) makes it easier to debug particular bugs if any of these tools fail&lt;/li&gt;
&lt;li&gt;A greater understanding of the individual tools will make it easier to extend or change any of the tools' behaviour later!&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Just want the code?
&lt;/h2&gt;

&lt;p&gt;With all of that said - if you'd rather just get up and running quickly, I've written a git repo with everything described in this guide. It's available &lt;a href="https://github.com/Sarghm/typescript-eslint-prettier-template" rel="noopener noreferrer"&gt;right here.&lt;/a&gt; &lt;/p&gt;

&lt;p&gt;If it's useful, I'd appreciate a star! ✨&lt;/p&gt;

&lt;p&gt;Still here? Alright! On with the show!&lt;/p&gt;

&lt;h2&gt;
  
  
  Installing TypeScript
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Step 1:&lt;/strong&gt; We'll start by creating a new folder to use as a root for our project. In your command line, enter the following command (replacing &lt;code&gt;my-new-project&lt;/code&gt; with your project's name):&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="nb"&gt;mkdir &lt;/span&gt;my-new-project
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;&lt;strong&gt;Step 2:&lt;/strong&gt; Next, we need to get our project set up using &lt;strong&gt;Yarn&lt;/strong&gt;. To do this, we'll need to enter the folder we've just created and initialise our project.&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="nb"&gt;cd &lt;/span&gt;my-new-project
yarn init
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;This should give us an interactive series of steps where we can enter all the relevant information for our project in.&lt;/p&gt;

&lt;p&gt;Enter values for all of these if you have anything specific, or just press Enter to use the defaults for each (shown in parentheses after each question).&lt;/p&gt;

&lt;p&gt;The only one to pay attention to is the &lt;strong&gt;entry point&lt;/strong&gt; - make sure you enter &lt;code&gt;./build/index.js&lt;/code&gt; rather than just &lt;code&gt;index.js&lt;/code&gt;. I'll highlight why later in the article.&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%2Fi.imgur.com%2FeuJIg30.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%2Fi.imgur.com%2FeuJIg30.png" alt="Yarn Init interactive steps"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 3:&lt;/strong&gt; Okay, now that we've initialised our project, let's go ahead and install TypeScript into our project. &lt;/p&gt;

&lt;p&gt;Using the same command line (still navigated to the &lt;code&gt;my-new-project&lt;/code&gt; directory), enter the following command:&lt;br&gt;
&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;yarn add typescript &lt;span class="nt"&gt;--dev&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;This will add TypeScript to our &lt;code&gt;devDependencies&lt;/code&gt;. For more information on the difference between &lt;code&gt;dependencies&lt;/code&gt; and &lt;code&gt;devDependencies&lt;/code&gt;, there's an article you can check out &lt;a href="https://medium.com/@dylanavery720/npmmmm-1-dev-dependencies-dependencies-8931c2583b0c#:~:text=The%20difference%20between%20these%20two,an%20npm%20install%20%2D%2Dsave." rel="noopener noreferrer"&gt;right here&lt;/a&gt;. &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 4:&lt;/strong&gt; After that's installed, we'll need to create ourselves a configuration file for TypeScript to use. &lt;/p&gt;

&lt;p&gt;To create that, enter the following command:&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="nb"&gt;touch&lt;/span&gt; ./tsconfig.json
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;&lt;strong&gt;Step 5:&lt;/strong&gt; Next, we'll create a folder to store our TypeScript files in, and create an &lt;code&gt;index.ts&lt;/code&gt; file to get started. Back in your command line, enter the following:&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="nb"&gt;mkdir&lt;/span&gt; ./src
&lt;span class="nb"&gt;touch&lt;/span&gt; ./src/index.ts
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;Great - now we've created a folder in our project's directory called &lt;code&gt;src&lt;/code&gt;, and created a single file called &lt;code&gt;index.ts&lt;/code&gt; inside.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 6:&lt;/strong&gt; Next, you'll want to open up the &lt;code&gt;tsconfig.json&lt;/code&gt; file that we just created, using VSCode. &lt;/p&gt;

&lt;p&gt;We're going to set our TypeScript's configuration up with the simplest settings possible, with the idea being that you can add to and extend this. Feel free to copy and paste the following configuration (feel free to remove the comments - they're not required, more just to let you know what each line does!)&lt;/p&gt;


&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Note:&lt;/strong&gt; If you're planning on setting this project up with React later down the line, there's a React-specific barebones &lt;code&gt;tsconfig.json&lt;/code&gt; you can refer to &lt;a href="https://gist.github.com/Sarghm/07140fcb4f835571af51b6f977a5e410" rel="noopener noreferrer"&gt;here&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;For more information on &lt;code&gt;tsconfig.json&lt;/code&gt; and all of the possible parameters you can use during setup, there's more information on the &lt;a href="https://www.typescriptlang.org/tsconfig" rel="noopener noreferrer"&gt;official TypeScript handbook.&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 7:&lt;/strong&gt; Finally, open up the &lt;strong&gt;root folder&lt;/strong&gt; (not just a single file!) - in VSCode.&lt;/p&gt;

&lt;p&gt;You should now be able to write TypeScript inside of your &lt;code&gt;index.ts&lt;/code&gt; file! Just make sure you create all your &lt;code&gt;.ts&lt;/code&gt; files inside of the &lt;code&gt;src&lt;/code&gt; folder (or a sub-directory inside &lt;code&gt;src&lt;/code&gt;) to ensure the compiler catches everything.&lt;/p&gt;

&lt;p&gt;To build your TypeScript into JavaScript files, simply run the following command from the root directory:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;yarn tsc &lt;span class="nt"&gt;-p&lt;/span&gt; ./tsconfig.json
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;h2&gt;
  
  
  ESLint
&lt;/h2&gt;

&lt;p&gt;Alright, let's get our codebase linted with ESLint!&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 1:&lt;/strong&gt; First, we'll want to install the relevant ESLint plugin for VSCode. Simply search for &lt;strong&gt;ESLint&lt;/strong&gt; in the Extensions bar on the left side of the screen, then hit &lt;strong&gt;Install&lt;/strong&gt; to install it.&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%2Fi.imgur.com%2FcBc3Dvc.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%2Fi.imgur.com%2FcBc3Dvc.png" alt="Installing ESLint in Visual Studio Code"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 2:&lt;/strong&gt; Open up your command line once again, and navigate to your project's root directory. From there, we want to install all the required libraries to get ESLint up and running.&lt;/p&gt;

&lt;p&gt;To do so, enter the following command:&lt;br&gt;
&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;yarn add eslint @typescript-eslint/eslint-plugin @typescript-eslint/parser --dev
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;This will install:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;eslint&lt;/strong&gt; - The ESLint core package&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;@typescript-eslint/eslint-plugin&lt;/strong&gt; - A plugin for ESLint to support TypeScript specifically&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;@typescript-eslint/parser&lt;/strong&gt; - Further support for ESLint to lint TypeScript source files&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Step 3:&lt;/strong&gt; Next, whilst we're still in the command line, we'll need to set up our configuration file for ESLint.&lt;/p&gt;

&lt;p&gt;To do so, enter the following command:&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="nb"&gt;touch&lt;/span&gt; .eslintrc
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;(Note the &lt;code&gt;.&lt;/code&gt; at the beginning of the &lt;code&gt;eslintrc&lt;/code&gt;. That's really important - make sure you don't miss it!)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 4:&lt;/strong&gt; To finish up the setup, we'll need to make some changes to the &lt;code&gt;.eslintrc&lt;/code&gt; file that we've just created. If you already have VSCode open, you should now be able to navigate to &lt;code&gt;.eslintrc&lt;/code&gt; in your project tree. &lt;/p&gt;

&lt;p&gt;Here's what that looks like on Visual Studio Code:&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%2Fi.imgur.com%2FyfitNxH.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%2Fi.imgur.com%2FyfitNxH.png" alt="Opening .eslintrc file up from the project tree in Visual Studio Code"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Now that &lt;code&gt;.eslintrc&lt;/code&gt; is open, update it so that it looks like the following:&lt;/p&gt;


&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;



&lt;p&gt;This configuration applies all of the libraries that we've just installed.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 5:&lt;/strong&gt; Restart VSCode!&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 6:&lt;/strong&gt; You should now be able to observe an &lt;code&gt;ESLint&lt;/code&gt; marker in the status bar (bottom right corner of the screen).&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%2Fi.imgur.com%2FIw5jfzL.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%2Fi.imgur.com%2FIw5jfzL.png" alt="Positive state for ESLint"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;If it looks like the image above - great! You're all set!&lt;/p&gt;

&lt;p&gt;However, if it looks like this:&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%2Fi.imgur.com%2F8T2rTYm.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%2Fi.imgur.com%2F8T2rTYm.png" alt="Error state for ESLint"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;...you'll need to click it, and then grant the workspace the necessary permissions to use ESLint. After that, one last IDE restart should get you up and running!&lt;/p&gt;

&lt;h2&gt;
  
  
  Prettier
&lt;/h2&gt;

&lt;p&gt;Almost there! Let's get our environment configured to use Prettier...&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 1:&lt;/strong&gt; Once again, open up your command line, and navigate to your project's root directory. We'll be installing a few new packages to add support for Prettier...&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;yarn add prettier eslint-config-prettier eslint-plugin-prettier &lt;span class="nt"&gt;--dev&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;&lt;strong&gt;Step 2:&lt;/strong&gt; Next, let's open up our &lt;code&gt;.eslintrc&lt;/code&gt; file and add those new libraries to the &lt;code&gt;extends&lt;/code&gt; array in our configuration...&lt;/p&gt;


&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;



&lt;p&gt;(&lt;strong&gt;Note:&lt;/strong&gt; The order in which the content of the &lt;code&gt;extends&lt;/code&gt; array is very important to ensure you don't have any trouble later on down the line!)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 3:&lt;/strong&gt; Finally - restart VSCode one last time.&lt;/p&gt;

&lt;p&gt;And that's it - feel free to breathe a sigh of relief. You've done it! You've set up a project with &lt;strong&gt;TypeScript&lt;/strong&gt;, &lt;strong&gt;ESLint&lt;/strong&gt; and &lt;strong&gt;Prettier!&lt;/strong&gt;&lt;/p&gt;

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

&lt;p&gt;It feels like a hell of a lot to do &lt;em&gt;just&lt;/em&gt; to get your environment ready, but I honestly believe that once you've gone through this process once and have an understanding as to how all the separate components come together, it really makes things a lot more straightforward in the event that any of these tools fail. Now that you've braved the storm, you should also be in a great position to customise ESLint and Prettier to your heart's content.&lt;/p&gt;

&lt;h2&gt;
  
  
  One last thing...
&lt;/h2&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%2Fi.imgur.com%2FTlmEDgZ.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%2Fi.imgur.com%2FTlmEDgZ.png" alt="CodeSnap promo image"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;I've made a &lt;strong&gt;16-part&lt;/strong&gt; TypeScript course, written specifically for JavaScript developers - and it's totally free. If you're interested, it's available to view on my &lt;a href="https://www.youtube.com/watch?v=vugSEGpPsEo&amp;amp;list=PL7siRj7spTbBfiNQ1kBVuytL8-I8DZWZq" rel="noopener noreferrer"&gt;YouTube channel right here&lt;/a&gt;. You can also support this content by subscribing to me, or just following me on here for more TypeScript content.&lt;/p&gt;

&lt;p&gt;Thanks so much for reading!&lt;/p&gt;

</description>
      <category>typescript</category>
      <category>javascript</category>
      <category>webdev</category>
      <category>react</category>
    </item>
    <item>
      <title>4 Must-Know TypeScript Tips &amp; Tricks</title>
      <dc:creator>Sam Piggott</dc:creator>
      <pubDate>Mon, 07 Dec 2020 09:21:08 +0000</pubDate>
      <link>https://dev.to/sam_piggott/4-must-know-typescript-tips-tricks-3g8b</link>
      <guid>https://dev.to/sam_piggott/4-must-know-typescript-tips-tricks-3g8b</guid>
      <description>&lt;p&gt;TypeScript has some incredibly nifty utilities that can be used to make your codebase more readable, efficient and safer. &lt;/p&gt;

&lt;p&gt;In this article, I've compiled a list of four of my favourite utilities that I use in my daily workflow, along with some examples and explanations of each. &lt;/p&gt;

&lt;p&gt;They've helped my TypeScript workflow - I hope they help yours, too!&lt;/p&gt;

&lt;h2&gt;
  
  
  Before we get started...
&lt;/h2&gt;

&lt;p&gt;If you're new to TypeScript, I have a full course for beginners available right here on my &lt;a href="https://www.youtube.com/watch?v=vugSEGpPsEo&amp;amp;list=PL7siRj7spTbBfiNQ1kBVuytL8-I8DZWZq" rel="noopener noreferrer"&gt;YouTube channel!&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;It covers all the essentials you need to get started with TypeScript as a JavaScript developer. &lt;/p&gt;

&lt;p&gt;If that sounds like something you're looking for, &lt;a href="https://www.youtube.com/watch?v=vugSEGpPsEo&amp;amp;list=PL7siRj7spTbBfiNQ1kBVuytL8-I8DZWZq" rel="noopener noreferrer"&gt;check it out here&lt;/a&gt; - I'd love to hear your thoughts on it!&lt;/p&gt;

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

&lt;p&gt;&lt;code&gt;Pick&lt;/code&gt; and &lt;code&gt;Omit&lt;/code&gt; are special utility types that TypeScript provides as a way to add more convenience and power when creating new types for object shapes. Let's take a look at each one in detail with some examples...&lt;/p&gt;

&lt;h3&gt;
  
  
  Pick
&lt;/h3&gt;

&lt;p&gt;In the following example, we've constructed an &lt;code&gt;interface&lt;/code&gt; type called &lt;code&gt;Consumable&lt;/code&gt;, which has got a bunch of properties that relate to something you could eat or drink.&lt;/p&gt;


&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;


&lt;p&gt;TypeScript provides the &lt;code&gt;Pick&lt;/code&gt; utility to allow us to "pluck" properties from our object shape types, and create a new type from that. Let's create a new type, &lt;code&gt;Pizza&lt;/code&gt;, by simply picking out the relevant properties from the &lt;code&gt;Consumable&lt;/code&gt; type.&lt;/p&gt;


&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;


&lt;p&gt;Nice! Let's go over that in a little more detail. &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;The first parameter that we pass into the &lt;code&gt;Pick&lt;/code&gt; utility is the type that we want to pick from. &lt;/li&gt;
&lt;li&gt;The second parameter is either a single value or a union type of all of the properties we want to pick out from the type we passed in as the first parameter.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;In the above example, we're picking &lt;code&gt;size&lt;/code&gt; and &lt;code&gt;caloriesPerServing&lt;/code&gt; from the &lt;code&gt;Consumable&lt;/code&gt; type to construct our brand new type, &lt;code&gt;Pizza&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;Let's go one step further. The cool thing about creating a new type is that we can use it just like anything else - so let's extrapolate our &lt;code&gt;Pizza&lt;/code&gt; type and add a &lt;code&gt;toppings&lt;/code&gt; property to our object shape...&lt;/p&gt;


&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;


&lt;p&gt;In this example, we're declaring &lt;code&gt;Pizza&lt;/code&gt; as an &lt;code&gt;interface&lt;/code&gt;, so that we can extend from our new &lt;code&gt;Pick&lt;/code&gt;ed type and add a brand new parameter, &lt;code&gt;toppings&lt;/code&gt;, to it. That means that our &lt;code&gt;Pizza&lt;/code&gt; interface, after being compiled, would have the following properties:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;size&lt;/strong&gt;: 'large' | 'medium' | 'small'&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;caloriesPerServing&lt;/strong&gt;: number&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;toppings&lt;/strong&gt;: string[]&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Omit
&lt;/h3&gt;

&lt;p&gt;Omit works just like &lt;code&gt;Pick&lt;/code&gt; - but the inverse. &lt;/p&gt;

&lt;p&gt;We pass &lt;code&gt;Pick&lt;/code&gt; the properties we wish to pluck out from the object type, but with &lt;code&gt;Omit&lt;/code&gt;, we pass the properties we wish to &lt;strong&gt;exclude&lt;/strong&gt; from the initial object type.&lt;/p&gt;

&lt;p&gt;Let's take a look at an example to make things a little clearer. Just like with &lt;code&gt;Pick&lt;/code&gt;, we'll use the same &lt;code&gt;Consumable&lt;/code&gt; type once again as a base - but this time, we'll create a new type called &lt;code&gt;Sandwich&lt;/code&gt;.&lt;/p&gt;


&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;


&lt;p&gt;Our &lt;code&gt;Consumable&lt;/code&gt; type has a property on it called &lt;code&gt;millilitresPerServing&lt;/code&gt;. That's not really relevant to a sandwich - so by using &lt;code&gt;Omit&lt;/code&gt;, we can pass in two arguments:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;First, the type that we wish to use as a base... &lt;/li&gt;
&lt;li&gt;...followed by a single or union type of the keys that we wish to &lt;strong&gt;omit&lt;/strong&gt; from that interface.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;(Just like with &lt;code&gt;Pick&lt;/code&gt;!)&lt;/p&gt;

&lt;p&gt;That means in this example, our &lt;code&gt;Sandwich&lt;/code&gt; type would have the following properties:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;size&lt;/strong&gt;: 'large' | 'medium' | 'small'&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;caloriesPerServing&lt;/strong&gt;: number&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;gramsPerServing&lt;/strong&gt;: number&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Notice that &lt;code&gt;millilitresPerServing&lt;/code&gt; isn't present in that list - that's because our &lt;code&gt;Sandwich&lt;/code&gt; type intentionally omits that from our new type by using the &lt;code&gt;Omit&lt;/code&gt; utility as described above.&lt;/p&gt;

&lt;p&gt;What's just as cool - just like with &lt;code&gt;Pick&lt;/code&gt;, the previous example, we can use the new type generated by the &lt;code&gt;Omit&lt;/code&gt; utility as a base to extend from. Let's extend our &lt;code&gt;Sandwich&lt;/code&gt; type by adding some &lt;code&gt;fillings&lt;/code&gt;...&lt;/p&gt;


&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;


&lt;p&gt;&lt;strong&gt;Omit&lt;/strong&gt; and &lt;strong&gt;Pick&lt;/strong&gt; really come into their own in more complex applications, particularly when you have a lot of overlapping object shapes that have properties which should remain identical in type. They're a dream for composition!&lt;/p&gt;

&lt;h2&gt;
  
  
  Required &amp;amp; Partial
&lt;/h2&gt;

&lt;p&gt;Just like &lt;code&gt;Pick&lt;/code&gt; and &lt;code&gt;Omit&lt;/code&gt; that we covered above, &lt;code&gt;Required&lt;/code&gt; and &lt;code&gt;Partial&lt;/code&gt; are utility types that allow us to create new types from our object types. Let's take a look into each one to see how they could be used as part of a workflow.&lt;/p&gt;

&lt;h3&gt;
  
  
  Required
&lt;/h3&gt;

&lt;p&gt;Okay, simple example - we have an interface for a (fictional) sign-up form on a website, with all the usual suspects present.&lt;/p&gt;


&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;


&lt;p&gt;Notice that in the above example, we've got a few &lt;code&gt;?&lt;/code&gt;s in there. &lt;/p&gt;

&lt;p&gt;Those are use to indicate that those properties are &lt;strong&gt;optional&lt;/strong&gt; - which means that they're allowed to be &lt;code&gt;undefined&lt;/code&gt;. Let's create an input object using our type:&lt;/p&gt;


&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;


&lt;p&gt;(Note: I could have also just omitted all of of the properties with &lt;code&gt;undefined&lt;/code&gt; as a value, but I wanted this example to be a bit more explicit for easy reading!)&lt;/p&gt;

&lt;p&gt;Let's say for example that we have another form in our web app elsewhere, which uses the same shape of input - but this time, requires that we supply values to &lt;strong&gt;all&lt;/strong&gt; of the properties in our &lt;code&gt;MyFormInputs&lt;/code&gt; object.&lt;/p&gt;

&lt;p&gt;If we wanted to, we could just re-write that same interface again, keeping all our keys and value types the same - but removing those pesky &lt;code&gt;?&lt;/code&gt;s to ensure that we can't pass any &lt;code&gt;undefined&lt;/code&gt; values in...&lt;/p&gt;


&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;


&lt;p&gt;...but, following the classic DRY rule, this should start to leave a bit of a bad taste in your mouth. There must be a better way...&lt;/p&gt;

&lt;p&gt;Thankfully, that's where the wonderful &lt;code&gt;Required&lt;/code&gt; utility comes in!&lt;/p&gt;

&lt;p&gt;Let's create a new type called &lt;code&gt;MyFormInputsRequired&lt;/code&gt; and make all of the properties on it non-nullable.&lt;/p&gt;


&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;


&lt;p&gt;&lt;code&gt;Required&lt;/code&gt; simply takes one parameter - the interface or object type that we want to make all properties enforced. In the above example, we also create a new object using that interface, and ensure that every single property has a corresponding value.&lt;/p&gt;

&lt;p&gt;If the key wasn't present in &lt;code&gt;requiredInputs&lt;/code&gt;, or if we supplied &lt;code&gt;null&lt;/code&gt; or &lt;code&gt;undefined&lt;/code&gt; as any of the values, this would throw an exception at compile-time. &lt;/p&gt;

&lt;p&gt;Nice and safe!&lt;/p&gt;

&lt;h3&gt;
  
  
  Partial
&lt;/h3&gt;

&lt;p&gt;&lt;code&gt;Partial&lt;/code&gt; is the exact opposite of &lt;code&gt;Required&lt;/code&gt; - instead of making all the properties in an interface or object type &lt;strong&gt;required&lt;/strong&gt;, it makes them all &lt;strong&gt;optional&lt;/strong&gt;. (if you've read this entire article from the top, you're probably beginning to notice a pattern...)&lt;/p&gt;

&lt;p&gt;Let's take a look at an example on how it could be used. We'll go back to videogames to maintain some semblance of variation...&lt;/p&gt;


&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;


&lt;p&gt;In the above example, we've introduced our &lt;code&gt;VideoGame&lt;/code&gt; interface, which has three properties on it which are all &lt;strong&gt;required&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;Let's say we wanted to create a new type making all of the properties &lt;strong&gt;optional&lt;/strong&gt;. We'll use the power of &lt;code&gt;Partial&lt;/code&gt; to make this happen...&lt;/p&gt;


&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;


&lt;p&gt;In the example above, we create a new type named &lt;code&gt;VideoGamePartial&lt;/code&gt;, and, just like how we used &lt;code&gt;Required&lt;/code&gt; above, we pass the &lt;code&gt;Partial&lt;/code&gt; utility a single object type.&lt;/p&gt;

&lt;p&gt;This creates a new type, copying the exact shape of the &lt;code&gt;VideoGame&lt;/code&gt; interface, but making all of the properties optional.&lt;/p&gt;

&lt;p&gt;When we create a new object using our new &lt;code&gt;VideoGamePartial&lt;/code&gt; type (as demonstrated in the &lt;code&gt;nintendoGame&lt;/code&gt; value at the bottom of the above example), we can see that we're able to skip two of the previously required values - &lt;code&gt;description&lt;/code&gt; and &lt;code&gt;ageRating&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;Taking this to an extreme, because &lt;code&gt;Partial&lt;/code&gt; makes &lt;strong&gt;all&lt;/strong&gt; of our properties optional, it would actually be valid to use that type to simply create an empty object...&lt;/p&gt;


&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;


&lt;p&gt;...but that's probably more of a hypothetical use-case, as I can't imagine that being super useful in day-to-day 😅&lt;/p&gt;

&lt;p&gt;Finally, topping it all off (and attempting to drive home how cool these utilities are) - let's use our new &lt;code&gt;Partial&lt;/code&gt; type as a base to extend from!&lt;/p&gt;


&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;


&lt;p&gt;In the above example, we create a new type called &lt;code&gt;SonyVideoGame&lt;/code&gt;, which extends from our &lt;code&gt;VideoGame&lt;/code&gt; type that has a set of properties which are all optional.&lt;/p&gt;

&lt;p&gt;We've then added a new (required!) type to it called &lt;code&gt;platform&lt;/code&gt;. That means that all of the properties (and their respective optional states would be as follows):&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;title&lt;/strong&gt;: string - &lt;strong&gt;Optional&lt;/strong&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;description&lt;/strong&gt;: string - &lt;strong&gt;Optional&lt;/strong&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;ageRating&lt;/strong&gt;: '3+' | '10+' | '16+' - &lt;strong&gt;Optional&lt;/strong&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;platform&lt;/strong&gt;: 'PS2' | 'PS3' | 'PS4' | 'PS5' - &lt;strong&gt;Required&lt;/strong&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Using composition and the power of TypeScript utilities, we've created a complex type which has a series of properties which are both optional &amp;amp; required. Neat, right?&lt;/p&gt;

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

&lt;p&gt;And that concludes our whistle-stop tour on some of TypeScript's powerful utilities that are provided with the language. There's plenty of others that you can delve into &lt;a href="https://www.typescriptlang.org/docs/handbook/intro.html" rel="noopener noreferrer"&gt;over at the TypeScript handbook&lt;/a&gt; - but these four are some of my favourites.&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%2Fi.imgur.com%2FQO9lI9f.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%2Fi.imgur.com%2FQO9lI9f.png" alt="CodeSnap Promo Image"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;If you're looking for more TypeScript learnings, I have a full video course on the basics of TypeScript over on my &lt;a href="https://codesnap.io/course/introduction-to-typescript" rel="noopener noreferrer"&gt;website at CodeSnap.io&lt;/a&gt;!&lt;/p&gt;

&lt;p&gt;Happy TypeScript'ing!&lt;/p&gt;

</description>
      <category>typescript</category>
      <category>javascript</category>
      <category>react</category>
      <category>webdev</category>
    </item>
    <item>
      <title>Getting started with TypeScript as a JavaScript developer</title>
      <dc:creator>Sam Piggott</dc:creator>
      <pubDate>Tue, 01 Dec 2020 21:22:41 +0000</pubDate>
      <link>https://dev.to/sam_piggott/getting-started-with-typescript-as-a-javascript-developer-4b3l</link>
      <guid>https://dev.to/sam_piggott/getting-started-with-typescript-as-a-javascript-developer-4b3l</guid>
      <description>&lt;p&gt;If you're a JavaScript developer, you might have heard of TypeScript already.&lt;/p&gt;

&lt;p&gt;Or maybe you've had a quick dip into it, but the merit isn't immediately obvious.&lt;/p&gt;

&lt;p&gt;Or perhaps your colleague hasn't stopped talking about it for the past two years, and you're keen to hear what all the hype's about.&lt;/p&gt;

&lt;p&gt;Personally speaking, I've experienced all three of the above - and when I was first digging in to TypeScript, I found it quite difficult to find all the answers I needed as a beginner/hobbyist in one place.&lt;/p&gt;

&lt;p&gt;I'm hoping that this article can:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Explain why you should bother learning TypeScript&lt;/li&gt;
&lt;li&gt;Show you the advantages of why I think TypeScript's fantastic
Demonstrate via examples the similarities between JavaScript and TypeScript&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Why bother with TypeScript?
&lt;/h2&gt;

&lt;p&gt;Let's start with an example. Spot the bug in this JavaScript code:&lt;/p&gt;


&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;


&lt;p&gt;Did you spot it? It's a fairly common mistake - our function multiply multiplies a passed number by two…but we've gone and passed it a string.&lt;/p&gt;

&lt;p&gt;We shouldn't be multiplying a string - we should be multiplying a number!&lt;/p&gt;

&lt;p&gt;What's worse - we could very easily miss this bug. After all, when we run this JavaScript - perhaps embedded as part of a website, or Node.js application, myNumber will just be NaN.&lt;/p&gt;

&lt;p&gt;Now, imagine if we passed myNumber to another function, with the intention of it to be used as a number. In the best case scenario, we'll be backtracking to find this not-so-obvious bug, and in the worst, our code is pushed live, and causes unexpected behaviour to our users!&lt;/p&gt;

&lt;p&gt;And this, right here, is one of the main reasons TypeScript was created. TypeScript catches these problems before they reach runtime, and instead, are caught at compile time (I'll get into what that means in just a minute…)&lt;/p&gt;

&lt;h2&gt;
  
  
  Okay, I'm intrigued. Show me some examples!
&lt;/h2&gt;

&lt;p&gt;Like a lot of developers out there, I learn best through examples. Let's check out some basic code snippets written in JavaScript, then see how each one could be written in TypeScript.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Example 1: Adding two numbers together&lt;/strong&gt;&lt;/p&gt;

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


&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;
 

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


&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;


&lt;p&gt;&lt;strong&gt;Example 2: Getting the first letter of a word&lt;/strong&gt;&lt;/p&gt;

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


&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;


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


&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;


&lt;p&gt;From these examples, you might be surprised with how similar writing TypeScript is to JavaScript is. At its core, TypeScript is just JavaScript, but with additional features to make life for a developer a little easier.&lt;/p&gt;

&lt;p&gt;I'll explain in a bit more detail in just a minute, but first, here's a more complex example:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Example 3: Create a new object, then access a value on it&lt;/strong&gt;&lt;/p&gt;

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


&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;


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


&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;


&lt;p&gt;It's what you already know, just with some extra bits and pieces that will make your development life so much easier in the long run.&lt;/p&gt;

&lt;h2&gt;
  
  
  Shameless Self-Plug
&lt;/h2&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%2Fi.imgur.com%2FZb7PfE3.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%2Fi.imgur.com%2FZb7PfE3.png" alt="Introduction to TypeScript Course Cover Photo"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;If you're enjoying reading this - I have a free Introduction to TypeScript video course available over on &lt;a href="https://www.youtube.com/watch?v=vugSEGpPsEo&amp;amp;list=PL7siRj7spTbBfiNQ1kBVuytL8-I8DZWZq" rel="noopener noreferrer"&gt;my YouTube channel!&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;I'll be uploading new parts to my channel every Wednesday but if you don't want to wait, you can visit &lt;a href="https://codesnap.io/introduction-to-typescript" rel="noopener noreferrer"&gt;here&lt;/a&gt; to download and binge the whole thing right away.&lt;/p&gt;

&lt;p&gt;Alright, back to the article…&lt;/p&gt;

&lt;h2&gt;
  
  
  TypeScript is (not so) secretly just JavaScript
&lt;/h2&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%2Fi.imgur.com%2FZLOe4ay.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%2Fi.imgur.com%2FZLOe4ay.png" alt="TypeScript-related programmer humour"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;(Sorry, couldn't resist.)&lt;/p&gt;

&lt;p&gt;The thing is, we could write TypeScript files to our heart's content; but not a single web browser out there could understand it right now.&lt;/p&gt;

&lt;p&gt;And therein lies the prestige. After all is said and done, TypeScript compiles into plain ol' JavaScript.&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%2Fi.imgur.com%2Fpw5Delc.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%2Fi.imgur.com%2Fpw5Delc.png" alt="Diagram describing the TypeScript compiler"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;TypeScript files are written with the &lt;code&gt;.ts&lt;/code&gt; file extension, and JavaScript is written with the &lt;code&gt;.js&lt;/code&gt; file extension. Modern browsers can't understand TypeScript files in their native form. So, we need to turn it into something that it can understand - JavaScript!&lt;/p&gt;

&lt;p&gt;This is where the TypeScript compiler comes in.&lt;br&gt;
Once we're ready to ship our TypeScript code, we can run the TypeScript compiler on our &lt;code&gt;.ts&lt;/code&gt; file(s), with a command like so:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;tsc -w ./index.ts - outFile ./index.js&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;After running this on our &lt;code&gt;index.ts&lt;/code&gt; TypeScript file, we should have an &lt;code&gt;index.js&lt;/code&gt; file ready that we can import into our website, use as part of a Node.js application, create a Chrome extension with - anything, really, that you can do with JavaScript!&lt;/p&gt;

&lt;p&gt;What's more, the compiler has another feature. It'll also tell us when we write bugs in our code, and even let us know how to fix it…&lt;/p&gt;
&lt;h2&gt;
  
  
  Uncovering bugs early
&lt;/h2&gt;

&lt;p&gt;Let's take that JavaScript example from the top of this article:&lt;/p&gt;


&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;


&lt;p&gt;…and let's write out what it would look like in TypeScript…&lt;/p&gt;


&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;


&lt;p&gt;Now, let's see what happens when we try to compile our TypeScript code above with the TypeScript compiler, as we learned in the previous section…&lt;/p&gt;

&lt;p&gt;&lt;code&gt;tsc ./index.ts - outFile ./index.js&lt;/code&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%2Fi.imgur.com%2FcMTx5q3.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%2Fi.imgur.com%2FcMTx5q3.png" alt="Terminal readout demonstrating a bad TypeScript compile"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Uh-oh. This can't be good.&lt;/p&gt;

&lt;p&gt;TypeScript created our &lt;code&gt;index.js&lt;/code&gt; file, but it tells us there's something wrong with our code. It's explicitly telling us that we can't pass a string to a function which requires our value argument to be a number…so let's fix that bug!&lt;/p&gt;


&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;


&lt;p&gt;Now, when we run it once again…&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%2Fi.imgur.com%2FY9LojyZ.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%2Fi.imgur.com%2FY9LojyZ.png" alt="TypeScript compiler showing no errors"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Hey, look! No errors!&lt;/p&gt;

&lt;p&gt;We can now deploy our &lt;code&gt;index.js&lt;/code&gt; file to wherever we want with the confidence that we don't have any type errors in our codebase.&lt;/p&gt;

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

&lt;p&gt;This is the tip of the iceberg. Not even the tip - it's almost like an ice-cube balanced on top of an iceberg. If you're excited by this, then I promise you that there's much more to be excited by with TypeScript. It's insanely convenient and helpful, but also ridiculously powerful.&lt;/p&gt;

&lt;p&gt;What's more; almost all of the major frontend frameworks (React.js, Vue, Angular) have TypeScript support nowadays - same with backend frameworks, too. You'll be able to write your TypeScript using the latest JavaScript features, but deploy JavaScript that works almost anywhere!&lt;/p&gt;

&lt;p&gt;That's all for this introduction - but I'll be posting more articles about TypeScript in the coming weeks.&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%2Fi.imgur.com%2FQO9lI9f.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%2Fi.imgur.com%2FQO9lI9f.png" alt="CodeSnap Logo"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;In the meantime, if you're interested in learning more TypeScript - my Introduction to TypeScript video course is available on my &lt;a href="https://codesnap.io/introduction-to-typescript" rel="noopener noreferrer"&gt;website, CodeSnap.io&lt;/a&gt;. &lt;/p&gt;

&lt;p&gt;It's got basically everything I've mentioned here stuffed into the first two videos - and there's sixteen videos in the entire course.&lt;/p&gt;

&lt;p&gt;If you're interested in checking out the course on YouTube, the playlist is available here, or, if you'd rather download and binge the entire thing, you can &lt;a href="https://codesnap.io/introduction-to-typescript" rel="noopener noreferrer"&gt;download it from here&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Thanks so much for reading - happy TypeScript'ing!&lt;/p&gt;

</description>
      <category>typescript</category>
      <category>javascript</category>
      <category>react</category>
    </item>
  </channel>
</rss>
