<?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: Madyan</title>
    <description>The latest articles on DEV Community by Madyan (@madyanalj).</description>
    <link>https://dev.to/madyanalj</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%2F447551%2Fda5fbff5-771f-4e93-a4a2-b206aa70533c.jpg</url>
      <title>DEV Community: Madyan</title>
      <link>https://dev.to/madyanalj</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/madyanalj"/>
    <language>en</language>
    <item>
      <title>TS Tip 💁‍♂️ Avoid the boilerplate with `typeof`</title>
      <dc:creator>Madyan</dc:creator>
      <pubDate>Fri, 14 Aug 2020 19:07:34 +0000</pubDate>
      <link>https://dev.to/madyanalj/ts-tip-reduce-boilerplate-with-typeof-2n36</link>
      <guid>https://dev.to/madyanalj/ts-tip-reduce-boilerplate-with-typeof-2n36</guid>
      <description>&lt;h1&gt;
  
  
  TLDR 😎
&lt;/h1&gt;

&lt;p&gt;&lt;iframe class="tweet-embed" id="tweet-1292936831114387456-219" src="https://platform.twitter.com/embed/Tweet.html?id=1292936831114387456"&gt;
&lt;/iframe&gt;

  // Detect dark theme
  var iframe = document.getElementById('tweet-1292936831114387456-219');
  if (document.body.className.includes('dark-theme')) {
    iframe.src = "https://platform.twitter.com/embed/Tweet.html?id=1292936831114387456&amp;amp;theme=dark"
  }



&lt;/p&gt;

&lt;h1&gt;
  
  
  What issue are we solving here? 🤔
&lt;/h1&gt;

&lt;p&gt;We all love TypeScript because it allows us to declare and enforce certain contracts for our types. E.g.&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="kr"&gt;interface&lt;/span&gt; &lt;span class="nx"&gt;User&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;devCommunityUsername&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kr"&gt;string&lt;/span&gt;
  &lt;span class="nx"&gt;awesomenessLevel&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kr"&gt;number&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now we can reuse this type everywhere the &lt;code&gt;User&lt;/code&gt; object is expected:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nx"&gt;iAmExpectingAUserHere&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;user&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;User&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="c1"&gt;// now I can safely access user.awesomenessLevel 🤩&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;However, there are instances where you have a huge object that you declare only once like:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;config&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="na"&gt;username&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Me&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="na"&gt;password&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;TheyAreWatching 😱&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="c1"&gt;// imagine many more properties here&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Say you want to reference the type of this object. However, you don't want to declare a type explicitly as it'll lead into duplication, and with duplication comes maintenance cost (e.g. every time you add a property you need to declare it for the sake of using it in this single instance 😒)&lt;/p&gt;

&lt;p&gt;&lt;a href="https://i.giphy.com/media/26BoDGStUAafwdZII/giphy.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://i.giphy.com/media/26BoDGStUAafwdZII/giphy.gif" alt="Thinking..." width="500" height="375"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h1&gt;
  
  
  Solution: type inference to the rescue 🦸‍♀️
&lt;/h1&gt;

&lt;p&gt;Turns out TypeScript has a special keyword to automatically infer the type of an existing object, which is exactly what we need here!&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="c1"&gt;// use `typeof`&lt;/span&gt;
&lt;span class="kd"&gt;type&lt;/span&gt; &lt;span class="nx"&gt;Config&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;typeof&lt;/span&gt; &lt;span class="nx"&gt;config&lt;/span&gt;

&lt;span class="c1"&gt;// this is the same as:&lt;/span&gt;
&lt;span class="kd"&gt;type&lt;/span&gt; &lt;span class="nx"&gt;Config&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="na"&gt;username&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kr"&gt;string&lt;/span&gt;
  &lt;span class="na"&gt;password&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kr"&gt;string&lt;/span&gt;
  &lt;span class="p"&gt;...&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="c1"&gt;// you can use it like 🤘&lt;/span&gt;
&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nx"&gt;doSomething&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;config&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;Config&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="p"&gt;...&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h1&gt;
  
  
  Looking for more TS tips? 👇
&lt;/h1&gt;

&lt;p&gt;I've recently started tweeting daily tips like the one above. If you've enjoyed it and want to continue learning, follow me for more &lt;a href="https://twitter.com/madyanalj"&gt;TypeScript tips&lt;/a&gt; ✨&lt;/p&gt;

&lt;p&gt;&lt;a href="https://i.giphy.com/media/JUB4yOluSaRRsiK0Kt/giphy.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://i.giphy.com/media/JUB4yOluSaRRsiK0Kt/giphy.gif" alt="Follow me for TypeScript tips" width="480" height="480"&gt;&lt;/a&gt;&lt;/p&gt;

</description>
      <category>typescript</category>
    </item>
    <item>
      <title>Enjoying TypeScript? Bring it to your DevTools 👩‍💻</title>
      <dc:creator>Madyan</dc:creator>
      <pubDate>Wed, 05 Aug 2020 20:44:52 +0000</pubDate>
      <link>https://dev.to/madyanalj/enjoying-typescript-bring-it-to-your-devtools-522i</link>
      <guid>https://dev.to/madyanalj/enjoying-typescript-bring-it-to-your-devtools-522i</guid>
      <description>&lt;p&gt;As web developers, TypeScript has revolutionised our development experience. It helped us catch bugs as we type our code, provided us with rich auto-completions allowing us to discover public interfaces of objects without having to read their source code and overall just made the JavaScript development experience much more fun! 🥳&lt;/p&gt;

&lt;p&gt;We tend to spend the majority of our time as developers in our IDEs, which is great since it is where TypeScript excels. However, TypeScript is yet to come to our second homes as web devs, our browsers DevTools 😢&lt;/p&gt;

&lt;p&gt;&lt;a href="https://i.giphy.com/media/Ln8jSiE0JXHtCaVxRa/giphy.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://i.giphy.com/media/Ln8jSiE0JXHtCaVxRa/giphy.gif" alt="I need you" width="280" height="350"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Have you ever tried writing a quick script in your browser's console to manipulate a page? It might have been some experimental code, or perhaps it was a bookmarklet to automate a task? Have you started writing code like this and wished you can get validation ahead of time rather than by trial and error?&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="nx"&gt;JSON&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;stringify&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
  &lt;span class="nx"&gt;myAwesomeObject&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="c1"&gt;// which argument was the spacing one again?&lt;/span&gt;
&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;Well I don't know about you, but I'm not patient enough to wait until Google supports TypeScript in their DevTools, so I've decided to take things into my own hands and build an Open Source Chrome Extension 🙌&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--mFtJ8NyZ--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/i/yg6mr0t69jfwo9j8102l.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--mFtJ8NyZ--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/i/yg6mr0t69jfwo9j8102l.png" alt="Console+ demo" width="734" height="226"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;This is still experimental, but you can try it out now by &lt;a href="https://chrome.google.com/webstore/detail/console%20/mdpcfmohggcepdncbognlniaiefdpnnf"&gt;downloading it from the Chrome Web Store&lt;/a&gt; 👈&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--HaIDjuWZ--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/i/cejl5p7fumqsttwq46ut.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--HaIDjuWZ--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/i/cejl5p7fumqsttwq46ut.png" alt="TypeScript All The Things meme" width="394" height="424"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Lastly, this is on Open Source project. Hence it wouldn't be awesome without the community's input and contributions. Please submit issues and/or PRs on GitHub to help improve the experience for yourself and other devs 🙏&lt;/p&gt;


&lt;div class="ltag-github-readme-tag"&gt;
  &lt;div class="readme-overview"&gt;
    &lt;h2&gt;
      &lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--A9-wwsHG--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev.to/assets/github-logo-5a155e1f9a670af7944dd5e12375bc76ed542ea80224905ecaf878b9157cdefc.svg" alt="GitHub logo"&gt;
      &lt;a href="https://github.com/madyanalj"&gt;
        madyanalj
      &lt;/a&gt; / &lt;a href="https://github.com/madyanalj/console-plus"&gt;
        console-plus
      &lt;/a&gt;
    &lt;/h2&gt;
    &lt;h3&gt;
      💻 Chrome DevTools extension that allows running TypeScript code from the browser.
    &lt;/h3&gt;
  &lt;/div&gt;
  &lt;div class="ltag-github-body"&gt;
    
&lt;div id="readme" class="md"&gt;
&lt;h1&gt;
Console+&lt;/h1&gt;
&lt;p&gt;Chrome extension which allows developers to run TypeScript code right from their browsers 💻&lt;/p&gt;
&lt;p&gt;&lt;a rel="noopener noreferrer" href="https://github.com/madyanalj/console-plusdemo.png"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--6NYZ_amb--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://github.com/madyanalj/console-plusdemo.png" alt="Demo"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;🗃 &lt;a href="https://chrome.google.com/webstore/detail/console%20/mdpcfmohggcepdncbognlniaiefdpnnf" rel="nofollow"&gt;Download from the Chrome Web Store&lt;/a&gt;&lt;/p&gt;
&lt;h2&gt;
Stack&lt;/h2&gt;
&lt;p&gt;TypeScript | Monaco Editor | Node v13 | Chrome Extension API | Parcel.js | ESLint | Jest&lt;/p&gt;
&lt;h2&gt;
Development&lt;/h2&gt;
&lt;ol&gt;
&lt;li&gt;Install dependencies using:
&lt;div class="highlight highlight-source-shell notranslate position-relative overflow-auto js-code-highlight"&gt;
&lt;pre&gt;npm install&lt;/pre&gt;

&lt;/div&gt;
&lt;/li&gt;
&lt;li&gt;Run the following to generate the Chrome Extension in &lt;code&gt;/dist&lt;/code&gt;:
&lt;div class="highlight highlight-source-shell notranslate position-relative overflow-auto js-code-highlight"&gt;
&lt;pre&gt;npm run build&lt;/pre&gt;

&lt;/div&gt;
&lt;/li&gt;
&lt;li&gt;Go to &lt;code&gt;chrome://extensions/&lt;/code&gt; and ensure "Developer mode" is on.&lt;/li&gt;
&lt;li&gt;Click on "Load unpacked" and select the &lt;code&gt;/dist&lt;/code&gt; directory.&lt;/li&gt;
&lt;li&gt;To make further changes, run &lt;code&gt;npm run build&lt;/code&gt; again then click on "Update".&lt;/li&gt;
&lt;/ol&gt;
&lt;h2&gt;
Contribution&lt;/h2&gt;
&lt;p&gt;Issues and Pull Requests are more than welcome.&lt;/p&gt;
&lt;/div&gt;

  &lt;/div&gt;
  &lt;div class="gh-btn-container"&gt;&lt;a class="gh-btn" href="https://github.com/madyanalj/console-plus"&gt;View on GitHub&lt;/a&gt;&lt;/div&gt;
&lt;/div&gt;



</description>
      <category>typescript</category>
      <category>devtools</category>
      <category>webdev</category>
      <category>showdev</category>
    </item>
  </channel>
</rss>
