<?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: Jaime A. Mendez</title>
    <description>The latest articles on DEV Community by Jaime A. Mendez (@jam65st).</description>
    <link>https://dev.to/jam65st</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%2F755948%2Fb0c75847-c1c6-4577-a63f-d95a21c0bd06.png</url>
      <title>DEV Community: Jaime A. Mendez</title>
      <link>https://dev.to/jam65st</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/jam65st"/>
    <language>en</language>
    <item>
      <title>Setting up a TypeScript project with IntelliJ IDEA</title>
      <dc:creator>Jaime A. Mendez</dc:creator>
      <pubDate>Thu, 24 Mar 2022 03:06:33 +0000</pubDate>
      <link>https://dev.to/jam65st/setting-up-a-typescript-project-with-intellij-idea-ojl</link>
      <guid>https://dev.to/jam65st/setting-up-a-typescript-project-with-intellij-idea-ojl</guid>
      <description>&lt;p&gt;&lt;strong&gt;&lt;a href="https://www.jetbrains.com/idea/" rel="noopener noreferrer"&gt;IntelliJ IDEA&lt;/a&gt;&lt;/strong&gt; is a powerful &lt;em&gt;Integrated Development Environment&lt;/em&gt; &lt;strong&gt;&lt;a href="https://en.wikipedia.org/wiki/Integrated_development_environment" rel="noopener noreferrer"&gt;IDE&lt;/a&gt;&lt;/strong&gt; developed by &lt;a href="https://www.jetbrains.com" rel="noopener noreferrer"&gt;JetBrains&lt;/a&gt; for the most rigorous development environments. You can trust this IDE. It includes almost all features desired by developers, a large community is in the background, and a great company is behind the lines.&lt;/p&gt;




&lt;p&gt;By default doesn't exist a &lt;strong&gt;TypeScript&lt;/strong&gt; project template in &lt;strong&gt;IntelliJ IDEA&lt;/strong&gt;. But don't worry, setting up a &lt;strong&gt;TS project&lt;/strong&gt; is really easy:&lt;/p&gt;

&lt;p&gt;&lt;small&gt;&lt;strong&gt;The first time you must follow steps one and two, also when you reinstall your IDE.&lt;/strong&gt;&lt;/small&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Ensure that you have the &lt;strong&gt;JavaScript and TypeScript&lt;/strong&gt; plugin installed (Preferences | Plugins).
&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F3j1bd1h04zmpgtiifkte.png" alt="IntelliJ IDEA | Preferences (window) | Plugins"&gt;
&lt;/li&gt;
&lt;li&gt;&lt;p&gt;You must have installed &lt;strong&gt;TypeScript&lt;/strong&gt; from your favorite package manager (npm, yarn, pnpm). Let's confirm on the application preferences the use of your &lt;strong&gt;TS&lt;/strong&gt; version. &lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F39i62l8dht9l1xeyrd3e.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F39i62l8dht9l1xeyrd3e.png" alt="IntelliJ IDEA | Preferences (window) | Languages &amp;amp; Frameworks | TypeScript"&gt;&lt;/a&gt;&lt;br&gt;
&lt;small&gt;&lt;strong&gt;The next steps are required to start a new TypeScript project.&lt;/strong&gt;&lt;/small&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;You must create a new project with a Node.js setup.&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F64rbbulj4jyhorygzepb.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F64rbbulj4jyhorygzepb.png" alt="IntelliJ IDEA | Files (menu) | New Project"&gt;&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Ensure that you are using the right Node Interpreter and Package Manager (npm, yarn, pnpm)&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F2yj4w6f6bj2k4nh9dam3.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F2yj4w6f6bj2k4nh9dam3.png" alt="IntelliJ IDEA | New Project"&gt;&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;At this moment, you have a new Node.js empty project. Before continuing with your setup, you must create the &lt;strong&gt;TypeScript&lt;/strong&gt; project initialing it to make their &lt;em&gt;tsconfig.json&lt;/em&gt; file:&lt;br&gt;
    &lt;/p&gt;
&lt;pre&gt;&lt;code&gt;tsc --init&lt;/code&gt;&lt;/pre&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Before contiuing, you need to have a clear basic structure for your project as:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;project

&lt;ul&gt;
&lt;li&gt;[ src | dev ] TS Source files

&lt;ul&gt;
&lt;li&gt;[ app | index | init | start | main ] initial TS file&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;[ prd | dist ]JS Compiled files

&lt;ul&gt;
&lt;li&gt;[ same name of TS file ] Initial JS file&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;... others in the project&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;To end this step, you must create the directories and your initial TS file. In my case, I created:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;learning_typescript

&lt;ul&gt;
&lt;li&gt;dev

&lt;ul&gt;
&lt;li&gt;app.ts&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;dist&lt;/li&gt;
&lt;li&gt;index.html&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;It's highly recommended that your &lt;strong&gt;tsconfig.json&lt;/strong&gt; file includes almost these directives in &lt;strong&gt;compiler Options&lt;/strong&gt;:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;em&gt;target&lt;/em&gt;: &lt;strong&gt;es2017&lt;/strong&gt; &lt;small&gt;(Set the JavaScript language version for emitted JavaScript and include compatible library declarations.)&lt;/small&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;em&gt;module&lt;/em&gt;: &lt;strong&gt;commonjs&lt;/strong&gt; &lt;small&gt;(Specify what module code is generated)&lt;/small&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;em&gt;rootDir&lt;/em&gt;: &lt;strong&gt;./dev&lt;/strong&gt; &lt;small&gt;(or src, Specify the root folder within your source files)&lt;/small&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;em&gt;moduleResolution&lt;/em&gt;: &lt;strong&gt;node&lt;/strong&gt; &lt;small&gt;(Specify how TypeScript looks up a file from a given module specifier)&lt;/small&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;em&gt;sourceMap&lt;/em&gt;: &lt;strong&gt;true&lt;/strong&gt; &lt;small&gt;(Create source map files for emitted JavaScript files)&lt;/small&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;em&gt;outDir&lt;/em&gt;: &lt;strong&gt;./dist&lt;/strong&gt; &lt;small&gt;(Specify an output folder for all emitted files)&lt;/small&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;em&gt;esModuleInterop&lt;/em&gt;:  &lt;strong&gt;true&lt;/strong&gt; &lt;small&gt;(Emit additional JavaScript to ease support for importing CommonJS modules. This enables &lt;em&gt;'allowSyntheticDefaultImports'&lt;/em&gt; for type compatibility)&lt;/small&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;em&gt;forceConsistenCasingInFileNames&lt;/em&gt;:  &lt;strong&gt;true&lt;/strong&gt; &lt;small&gt;(Ensure that casing is correct in imports)&lt;/small&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;em&gt;strict&lt;/em&gt;: &lt;strong&gt;true&lt;/strong&gt; &lt;small&gt;(Enable all strict type-checking options)&lt;/small&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;em&gt;skipLibCheck&lt;/em&gt;:  &lt;strong&gt;true&lt;/strong&gt; &lt;small&gt;(Skip type checking all .d.ts files)&lt;/small&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Your typescript project looks good, but is not working yet, in this step you must configure the eslint tool.&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;eslint --init&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;And you must confirm any parameters such as (use your own choices):&lt;br&gt;
Ok to proceed? (y) &lt;strong&gt;y&lt;/strong&gt;&lt;br&gt;&lt;br&gt;
✔ How would you like to use ESLint? · &lt;strong&gt;style&lt;/strong&gt;&lt;br&gt;
✔ What type of modules does your project use? · &lt;strong&gt;esm&lt;/strong&gt;&lt;br&gt;
✔ Which framework does your project use? · &lt;strong&gt;react&lt;/strong&gt;&lt;br&gt;
✔ Does your project use TypeScript? · No / &lt;strong&gt;Yes&lt;/strong&gt;&lt;br&gt;
✔ Where does your code run? · &lt;strong&gt;browser&lt;/strong&gt;&lt;br&gt;
✔ How would you like to define a style for your project? · &lt;strong&gt;guide&lt;/strong&gt;&lt;br&gt;
✔ Which style guide do you want to follow? · &lt;strong&gt;airbnb&lt;/strong&gt;&lt;br&gt;
✔ What format do you want your config file to be in? · &lt;strong&gt;JSON&lt;/strong&gt;&lt;br&gt;
Then the initializer will check any peer dependencies.&lt;br&gt;
✔ Would you like to install them now with npm? · No / &lt;strong&gt;Yes&lt;/strong&gt;&lt;br&gt;
At this moment, your project has a new file: .eslintrc.json, but if you want to use the console, you need to allow it feature by modifying the rules adding a new:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;"rules": {
"noConsole": false
}&lt;/code&gt;&lt;/pre&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Your file &lt;strong&gt;package.json&lt;/strong&gt; was updated with the proper devDependencies. Let's go to update some features of our &lt;strong&gt;package.json&lt;/strong&gt; file with your choices:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;
"main": "./dist/app.js",
"script": {
"start": "tsc &amp;amp;&amp;amp; node dist/app.js",
...
},
"devDependencies": {
...
"eslint": "^8.11.0", //(Your current version and before of eslint elements)
"typescript": "^4.6.2" //(Your current version and before of eslint elements)
}&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;As a good practice, I encourage you to set or update your version, description, keywords, author, and license.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Great, but we need to perform a pair of duties more by setup &lt;strong&gt;TypeScript&lt;/strong&gt; in our &lt;strong&gt;IntelliJ Idea&lt;/strong&gt;, to do it, you got to &lt;strong&gt;Run/Edit&lt;/strong&gt; Configurations menu. &lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fwxwk7dj9kd5px95cibda.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fwxwk7dj9kd5px95cibda.png" alt="IntelliJ IDEA | Run (menu)"&gt;&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;We add new configuration (use any of the arrows) &lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fxycgyxw0xxzgb8r8ba5e.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fxycgyxw0xxzgb8r8ba5e.png" alt="IntelliJ IDEA | Run/Debug Configuration (window) | Init "&gt;&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;And choose a Node.js configuration&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fp9ib3dgnr0katr2k77sc.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fp9ib3dgnr0katr2k77sc.png" alt="IntelliJ IDEA | Run/Debug Configuration (window) | Add New Configuration"&gt;&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Update your &lt;strong&gt;JavaScript file&lt;/strong&gt; according to your basic structure, and your &lt;strong&gt;package.json&lt;/strong&gt; file. Also, it is mandatory that you implement a new &lt;em&gt;Before launch task&lt;/em&gt;, choose in the menu: &lt;strong&gt;Compile Typescript&lt;/strong&gt;. &lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fbzj67swzu4y3q5o075g0.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fbzj67swzu4y3q5o075g0.png" alt="IntelliJ IDEA | Run/Debug Configuration (window) | Node.js"&gt;&lt;/a&gt;&lt;br&gt;
And allocate your &lt;strong&gt;tsconfig.json&lt;/strong&gt; file. &lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fmkrws8mj41mryw48dxym.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fmkrws8mj41mryw48dxym.png" alt="IntelliJ IDEA | TypeScript Compile Settings (window)"&gt;&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Well, at this moment, our project looks something like this:&lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Filvq6fdpjtptixza53gn.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Filvq6fdpjtptixza53gn.png" alt="IntelliJ IDEA | Project (tab)"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;And it is great, but now we will test it.&lt;/p&gt;

&lt;p&gt;In your app.ts file we can write:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;const a = "1";
console.log( `Say hello world!!! ${a}`);
console.error( 'HAS type error', a.foo() );
console.error( 'NOT type error', a );&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;And immediately the Lint in IntelliJ idea shows an error:&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fd5utu7nic4xlg3qw5a6n.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fd5utu7nic4xlg3qw5a6n.png" alt="IntelliJ IDEA | Code (tab)"&gt;&lt;/a&gt;&lt;br&gt;
It is because &lt;strong&gt;a&lt;/strong&gt; constant doesn't have a foo function property, in fact, the &lt;em&gt;DataType&lt;/em&gt; is a &lt;strong&gt;String&lt;/strong&gt;. This error doesn't allow us to run our project.&lt;/p&gt;

&lt;p&gt;But if we comment on the third line (were appears a.foo method)&lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fvm5pxczcaslp52qud10d.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fvm5pxczcaslp52qud10d.png" alt="IntelliJ IDEA | Code (tab)"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Then the error is off of our test and can be run, as result in our &lt;strong&gt;run console&lt;/strong&gt; we can see:&lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fk4c2t4g3kjjfirlr12eb.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fk4c2t4g3kjjfirlr12eb.png" alt="IntelliJ IDEA | Run (tab)"&gt;&lt;/a&gt;&lt;/p&gt;




&lt;p&gt;Thanks for reading, now you can work on your own project. Enjoy it.&lt;/p&gt;

&lt;p&gt;If do you want copy or fork the project, this is available on &lt;a href="https://github.com/jam65st/LearningTypeScript" rel="noopener noreferrer"&gt;GitHub&lt;/a&gt;&lt;/p&gt;

</description>
      <category>tutorial</category>
      <category>beginners</category>
      <category>typescript</category>
      <category>node</category>
    </item>
  </channel>
</rss>
