<?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: Orji Chidi Matthew</title>
    <description>The latest articles on DEV Community by Orji Chidi Matthew (@chidimo).</description>
    <link>https://dev.to/chidimo</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%2F336139%2Fbb46620a-3c9e-48f2-a6b5-a149d4fba8cd.jpeg</url>
      <title>DEV Community: Orji Chidi Matthew</title>
      <link>https://dev.to/chidimo</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/chidimo"/>
    <language>en</language>
    <item>
      <title>Converting a React project to TypeScript - Avoid pain by using correct file extension</title>
      <dc:creator>Orji Chidi Matthew</dc:creator>
      <pubDate>Fri, 17 Dec 2021 14:52:31 +0000</pubDate>
      <link>https://dev.to/chidimo/converting-a-react-project-to-typescript-avoid-pain-by-using-correct-file-extension-jid</link>
      <guid>https://dev.to/chidimo/converting-a-react-project-to-typescript-avoid-pain-by-using-correct-file-extension-jid</guid>
      <description>&lt;p&gt;I recently decided to make the switch from writing pure JavaScript to writing TypeScript going forward. Like with all things that one can learn, watching all the tutorials in the world won't make much difference unless you actively apply your learning. That much is true for me, at least.&lt;/p&gt;

&lt;p&gt;To that end, I decided to convert one of my React projects to TypeScript. To accomplish that I did some research and eventually settled on using &lt;a href="https://github.com/airbnb/ts-migrate"&gt;ts-migrate&lt;/a&gt;, from the good folks at Airbnb. According the project homepage&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;em&gt;ts-migrate&lt;/em&gt; is intended to accelerate the TypeScript migration process.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;The migration process itself is not difficult if you just follow the instructions on the project homepage. However, having followed the instructions, I still experienced a lot of avoidable pain which were directly traceable to file extensions.&lt;/p&gt;

&lt;p&gt;Before running ts-migrate against your React codebase, you want to get your file extensions right. Small point, but big pain if not done. Normally, when I write React, I take the liberty of naming all files with a &lt;code&gt;.js&lt;/code&gt; extension. This is all okay since the &lt;code&gt;vs-code&lt;/code&gt; linter is smart enough to know which files should supposedly have a &lt;code&gt;.jsx&lt;/code&gt; extension. The real pain comes when all your component/container files end with &lt;code&gt;.js&lt;/code&gt; and you run ts-migrate against them. In my case, some of the files were converted to &lt;code&gt;.tsx&lt;/code&gt; but the majority were converted to &lt;code&gt;.ts&lt;/code&gt; extension. Consequently, there was a lot of avoidable errors that prevented the project from compiling. This cost me time going through dozens of files to remove those errors. Eventually, I also had to rename the affected files. Luckily, I found this &lt;a href="https://marketplace.visualstudio.com/items?itemName=JannisX11.batch-rename-extension"&gt;Batch Rename&lt;/a&gt; utility in the &lt;code&gt;vs-code&lt;/code&gt; marketplace.&lt;/p&gt;

&lt;p&gt;So lesson learned going forward - sure I still have some projects I may convert - is to rename all my react component files with a &lt;code&gt;.jsx&lt;/code&gt; extension before attempting a migration.&lt;/p&gt;

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