<?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: Max Kovalevsky</title>
    <description>The latest articles on DEV Community by Max Kovalevsky (@kovalevsky).</description>
    <link>https://dev.to/kovalevsky</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%2F130693%2F0035dfc5-aa54-4765-b0df-89f3ad7fc7e5.png</url>
      <title>DEV Community: Max Kovalevsky</title>
      <link>https://dev.to/kovalevsky</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/kovalevsky"/>
    <language>en</language>
    <item>
      <title>I curate a daily newsletter with resources about Golang - Daily Golang. Here are the latest 6 issues of the newsletter</title>
      <dc:creator>Max Kovalevsky</dc:creator>
      <pubDate>Mon, 19 Aug 2024 13:52:12 +0000</pubDate>
      <link>https://dev.to/kovalevsky/i-curate-a-daily-newsletter-with-resources-about-golang-daily-golang-here-are-the-latest-6-issues-of-the-newsletter-5e4g</link>
      <guid>https://dev.to/kovalevsky/i-curate-a-daily-newsletter-with-resources-about-golang-daily-golang-here-are-the-latest-6-issues-of-the-newsletter-5e4g</guid>
      <description>&lt;p&gt;Hello everyone!&lt;/p&gt;

&lt;p&gt;Not a while ago I started to run a &lt;a href="https://kovalevsky.io/daily-golang" rel="noopener noreferrer"&gt;daily newsletter with resources (blog posts, videos and projects) about Go (Golang) that I found interesting&lt;/a&gt;. Here are the latest 6 issues of the newsletter. I hope you will find it useful. Happy coding!&lt;/p&gt;

&lt;h1&gt;
  
  
  Daily Golang Issue #6 (2024-08-19)
&lt;/h1&gt;

&lt;h3&gt;
  
  
  Your daily hub for Go news, insights, and projects
&lt;/h3&gt;

&lt;h2&gt;
  
  
  ⚡️ Latest
&lt;/h2&gt;

&lt;p&gt;Here are the newest blog posts, videos, and projects from the Go community and all around it.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;GopherCon UK published recordings of talks from the latest conference

&lt;ul&gt;
&lt;li&gt;📹 &lt;a href="https://www.youtube.com/watch?v=pLvZRnK2WRE" rel="noopener noreferrer"&gt;The Business of Go - Cameron Balahan, Google&lt;/a&gt; &lt;/li&gt;
&lt;li&gt;📹 &lt;a href="https://www.youtube.com/watch?v=7YfFBTkGIOI" rel="noopener noreferrer"&gt;Debugging Go Applications - Matt Boyle, Cloudflare&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;📹 &lt;a href="https://www.youtube.com/watch?v=arH3jp_x8yQ" rel="noopener noreferrer"&gt;Understanding the Go runtime, Jesús Espino, Mattermost&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;📹 &lt;a href="https://www.youtube.com/watch?v=0GkRJQ1aUOI" rel="noopener noreferrer"&gt;Boost application performance with profile guided optimization Michael Pratt, Google&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;📹 &lt;a href="https://www.youtube.com/watch?v=eUIPFRNxDV8" rel="noopener noreferrer"&gt;AI is coming for your job - Adam Scholey, Benefex&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;📹 &lt;a href="https://www.youtube.com/watch?v=mls9mQFgB7A" rel="noopener noreferrer"&gt;Improving your code craft with generative AI - Liam Hampton, Microsoft&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;📹 &lt;a href="https://www.youtube.com/watch?v=gSPjoNczOsI" rel="noopener noreferrer"&gt;Decoding AI: A Go Programmer's Perspective - Beth Anderson, BBC&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;📹 &lt;a href="https://www.youtube.com/watch?v=zpP8aMqEna0" rel="noopener noreferrer"&gt;Event Driven Workflows - Andrew Wormald, Luno&lt;/a&gt;
&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;li&gt;📝 &lt;a href="https://www.jvt.me/posts/2024/08/16/gophercon-uk-2024/" rel="noopener noreferrer"&gt;GopherCon UK 2024&lt;/a&gt; by Jamie Tanna&lt;/li&gt;

&lt;li&gt;🛠️ &lt;a href="https://github.com/bilbilak/treegen" rel="noopener noreferrer"&gt;TreeGen&lt;/a&gt;

&lt;ul&gt;
&lt;li&gt;ASCII Tree to Directory and File Structure Generator&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;/ul&gt;

&lt;h2&gt;
  
  
  🧭 Discoveries
&lt;/h2&gt;

&lt;p&gt;Here is the list of discovered interesting blog posts, videos, and projects that are worth checking out.&lt;/p&gt;

&lt;h3&gt;
  
  
  📝 Blog Posts
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;a href="https://threedots.tech/post/safer-enums-in-go/" rel="noopener noreferrer"&gt;Safer Enums in Go&lt;/a&gt;

&lt;ul&gt;
&lt;li&gt;This post explores how to implement safer enums in Go, providing strategies to avoid common errors associated with enums and ensuring type safety in your code.&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;li&gt;

&lt;a href="https://bitfieldconsulting.com/posts/random-testing" rel="noopener noreferrer"&gt;Random testing in Go&lt;/a&gt; by John Arundel&lt;/li&gt;

&lt;li&gt;

&lt;a href="https://eli.thegreenplace.net/2024/sign-in-with-google-in-go/" rel="noopener noreferrer"&gt;Sign in with Google in Go&lt;/a&gt;

&lt;ul&gt;
&lt;li&gt;This post walks you through implementing Google OAuth authentication in a Go application. It covers setting up OAuth credentials, integrating with Google's API, and handling user sign-ins securely within your Go projects.&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;li&gt;

&lt;a href="https://www.dolthub.com/blog/2023-03-29-interactive-shell-golang/" rel="noopener noreferrer"&gt;Building an interactive shell in Golang&lt;/a&gt;

&lt;ul&gt;
&lt;li&gt;The author provides a guide to creating an interactive command-line shell in Go. The post covers topics like handling user input, executing commands, and managing the shell's environment, offering a practical approach to building robust CLI tools.&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;/ul&gt;

&lt;h3&gt;
  
  
  📹 Videos
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://www.youtube.com/watch?v=QFpneG6SVxw&amp;amp;list=PLCqcI2Ic-eM_RWwxxOvRBmt6jTNP8L5lP&amp;amp;index=72" rel="noopener noreferrer"&gt;Julia Ogris - Building a Beginner's Programming Language with Go | GopherConAU 2023&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://www.youtube.com/watch?v=xvPmJQ7U1A8&amp;amp;list=PLCqcI2Ic-eM_RWwxxOvRBmt6jTNP8L5lP&amp;amp;index=90" rel="noopener noreferrer"&gt;Why Golang + HTMX Is The Most Productive Stack&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://www.youtube.com/watch?v=yEcabpza3XA&amp;amp;list=PLCqcI2Ic-eM_RWwxxOvRBmt6jTNP8L5lP&amp;amp;index=60" rel="noopener noreferrer"&gt;Keynote - Go: the language of dreamers / Derek Parker&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://www.youtube.com/watch?v=iv5aRdslb5k&amp;amp;list=PLCqcI2Ic-eM_RWwxxOvRBmt6jTNP8L5lP&amp;amp;index=105" rel="noopener noreferrer"&gt;A REAL usecase of Golang Go Routines! - Golang  Concurrency Example&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  🛠️ Projects
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;a href="https://github.com/Sirupsen/logrus" rel="noopener noreferrer"&gt;sirupsen/logrus&lt;/a&gt;

&lt;ul&gt;
&lt;li&gt;Logrus is a structured, pluggable logging library for Go, designed to provide a flexible logging framework that supports various output formats and hooks.&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;li&gt;

&lt;a href="https://github.com/fergusstrange/embedded-postgres" rel="noopener noreferrer"&gt;fergusstrange/embedded-postgres&lt;/a&gt;

&lt;ul&gt;
&lt;li&gt;Embedded Postgres allows running a real Postgres database locally as part of another Go application or test, providing a simple way to include Postgres in your development environment.&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;/ul&gt;




&lt;h1&gt;
  
  
  Daily Golang Issue #5 (2024-08-18)
&lt;/h1&gt;

&lt;h3&gt;
  
  
  Your daily hub for Go news, insights, and projects
&lt;/h3&gt;

&lt;h2&gt;
  
  
  ⚡️ Latest
&lt;/h2&gt;

&lt;p&gt;Here are the newest blog posts, videos, and projects from the Go community and all around it.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;​&lt;a href="https://preview.convertkit-mail2.com/click/dpheh0hzhm/aHR0cHM6Ly93d3cueW91dHViZS5jb20vd2F0Y2g_dj10T0VTUGl0VFZ3RQ==" rel="noopener noreferrer"&gt;Go 1.23: What You Need to Know About the Latest Features&lt;/a&gt;​&lt;/li&gt;
&lt;li&gt;​&lt;a href="https://preview.convertkit-mail2.com/click/dpheh0hzhm/aHR0cHM6Ly9rb2thZGEuY2FwaXZhcmFzLmRldi9ibG9nL2FuLXVub3JkZXJlZC1saXN0LW9mLXRoaW5ncy1pLW1pc3MtaW4tZ28v" rel="noopener noreferrer"&gt;An unordered list of things I miss in Go&lt;/a&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  🧭 Discoveries
&lt;/h2&gt;

&lt;p&gt;Here is the list of discovered interesting blog posts, videos, and projects that are worth checking out.&lt;/p&gt;

&lt;h3&gt;
  
  
  📝 Blog Posts
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;a href="https://www.calhoun.io/moving-towards-domain-driven-design-in-go/" rel="noopener noreferrer"&gt;Moving Towards Domain Driven Design in Go&lt;/a&gt;

&lt;ul&gt;
&lt;li&gt;This post discusses how to implement Domain-Driven Design (DDD) principles in Go applications. The author provides practical steps to transition from traditional application structures to DDD, focusing on aligning code with business domains for better maintainability.&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;li&gt;

&lt;a href="https://bitfieldconsulting.com/posts/wrapping-errors" rel="noopener noreferrer"&gt;Error wrapping in Go&lt;/a&gt; by John Arundel&lt;/li&gt;

&lt;li&gt;

&lt;a href="https://threedots.tech/post/common-anti-patterns-in-go-web-applications/" rel="noopener noreferrer"&gt;Common Anti-Patterns in Go Web Applications&lt;/a&gt;

&lt;ul&gt;
&lt;li&gt;The author identifies and explains several common anti-patterns in Go web applications, offering advice on how to avoid these pitfalls to create more efficient and maintainable code.&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;li&gt;&lt;a href="https://notes.eatonphil.com/2023-05-25-raft.html" rel="noopener noreferrer"&gt;Implementing the Raft distributed consensus protocol in Go&lt;/a&gt;&lt;/li&gt;

&lt;/ul&gt;

&lt;h3&gt;
  
  
  📹 Videos
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://www.youtube.com/watch?v=sDTJMm__DXE&amp;amp;list=PLCqcI2Ic-eM_RWwxxOvRBmt6jTNP8L5lP&amp;amp;index=78" rel="noopener noreferrer"&gt;Raghav Roy - Coroutines and Go | GopherConAU 2023&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://www.youtube.com/watch?v=UjhpyjVMfuo&amp;amp;list=PLCqcI2Ic-eM_RWwxxOvRBmt6jTNP8L5lP&amp;amp;index=91" rel="noopener noreferrer"&gt;Golang Has Entered a New Era for Routing&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://www.youtube.com/watch?v=dKUiCF3abHc&amp;amp;list=PLCqcI2Ic-eM_RWwxxOvRBmt6jTNP8L5lP&amp;amp;index=128" rel="noopener noreferrer"&gt;How to EFFICIENTLY Handle Errors in Golang APIs&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://www.youtube.com/watch?v=Ax7J_Ks0UWs&amp;amp;list=PLCqcI2Ic-eM_RWwxxOvRBmt6jTNP8L5lP&amp;amp;index=185" rel="noopener noreferrer"&gt;How To Refactor A Golang Project By Using Interfaces&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  🛠️ Projects
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;a href="https://github.com/spf13/viper" rel="noopener noreferrer"&gt;spf13/viper&lt;/a&gt;

&lt;ul&gt;
&lt;li&gt;A popular configuration management library in Go, supporting many formats, environment variables, remote configurations, and more, designed to work seamlessly with spf13/cobra.&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;li&gt;

&lt;a href="https://github.com/rqlite/rqlite" rel="noopener noreferrer"&gt;rqlite/rqlite&lt;/a&gt;

&lt;ul&gt;
&lt;li&gt;Rqlite is a lightweight, distributed relational database built on SQLite, offering an easy-to-use solution for applications requiring high availability and fault tolerance.&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;/ul&gt;




&lt;h1&gt;
  
  
  Daily Golang Issue #4 (2024-08-17)
&lt;/h1&gt;

&lt;h3&gt;
  
  
  Your daily hub for Go news, insights, and projects
&lt;/h3&gt;

&lt;h2&gt;
  
  
  🧭 Discoveries
&lt;/h2&gt;

&lt;p&gt;Here is the list of discovered interesting blog posts, videos, and projects that are worth checking out.&lt;/p&gt;

&lt;h3&gt;
  
  
  📝 Blog Posts
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;a href="https://bitfieldconsulting.com/posts/testscript-tool" rel="noopener noreferrer"&gt;Standalone test scripts&lt;/a&gt; by John Arundel&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://www.calhoun.io/using-functional-options-instead-of-method-chaining-in-go/" rel="noopener noreferrer"&gt;Using functional options instead of method chaining in Go&lt;/a&gt;

&lt;ul&gt;
&lt;li&gt;Jon Calhoun advocates for the use of functional options as an alternative to method chaining in Go, explaining how this pattern can lead to more flexible and maintainable code.&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;li&gt;

&lt;a href="https://threedots.tech/post/ddd-lite-in-go-introduction/" rel="noopener noreferrer"&gt;Introduction to DDD Lite: When microservices in Go are not enough&lt;/a&gt;

&lt;ul&gt;
&lt;li&gt;This article introduces a "DDD Lite" approach, explaining how it can be a middle ground between full-blown Domain-Driven Design (DDD) and simpler design patterns. It’s particularly useful when microservices alone do not sufficiently address complex business needs.&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;li&gt;&lt;a href="https://zenhorace.dev/blog/context-control-go/" rel="noopener noreferrer"&gt;Context Control in Go&lt;/a&gt;&lt;/li&gt;

&lt;/ul&gt;

&lt;h3&gt;
  
  
  📹 Videos
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://www.youtube.com/watch?v=MYtUOOizITs&amp;amp;list=PLCqcI2Ic-eM_RWwxxOvRBmt6jTNP8L5lP&amp;amp;index=2" rel="noopener noreferrer"&gt;The Secret Life of a Goroutine - Jesús Espino - April Gophers 2023&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://www.youtube.com/watch?v=DZIhkFLVNqc&amp;amp;list=PLCqcI2Ic-eM_RWwxxOvRBmt6jTNP8L5lP&amp;amp;index=39" rel="noopener noreferrer"&gt;GopherCon 2023: Ellery Addington-White - From Zero to Hero: Launch Your Own Game in 45 Minutes&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://www.youtube.com/watch?v=PLlEym5JVvM&amp;amp;list=PLCqcI2Ic-eM_RWwxxOvRBmt6jTNP8L5lP&amp;amp;index=71" rel="noopener noreferrer"&gt;06. Matteo Grella - The Go-to Language for AI: Opportunities and Challenges | GopherConAU 2023&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://www.youtube.com/watch?v=LGVRPFZr548&amp;amp;list=PLCqcI2Ic-eM_RWwxxOvRBmt6jTNP8L5lP&amp;amp;index=174" rel="noopener noreferrer"&gt;How To Use Goroutines For Aggregating Data In Golang?!&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  🛠️ Projects
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;a href="https://github.com/go-task/task" rel="noopener noreferrer"&gt;go-task/task&lt;/a&gt;

&lt;ul&gt;
&lt;li&gt;simple "Make" alternative.&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;li&gt;

&lt;a href="https://github.com/joho/godotenv" rel="noopener noreferrer"&gt;joho/godotenv)&lt;/a&gt;

&lt;ul&gt;
&lt;li&gt;A Go port of the Ruby dotenv library, which loads environment variables from a &lt;code&gt;.env&lt;/code&gt; file, making it easier to manage environment-specific configurations.&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;/ul&gt;




&lt;h1&gt;
  
  
  Daily Golang Issue #3 (2024-08-16)
&lt;/h1&gt;

&lt;h3&gt;
  
  
  Your daily hub for Go news, insights, and projects
&lt;/h3&gt;

&lt;h2&gt;
  
  
  ⚡️ Latest
&lt;/h2&gt;

&lt;p&gt;Here are the newest blog posts, videos, and projects from the Go community and all around it.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;a href="https://preview.convertkit-mail2.com/click/dpheh0hzhm/aHR0cHM6Ly93d3cubWFyYWd1LmRldi9ibG9nL2dvLWlzLW15LWhhbW1lci1hbmQtZXZlcnl0aGluZy1pcy1hLW5haWw=" rel="noopener noreferrer"&gt;Go is my hammer, and everything is a nail&lt;/a&gt;​&lt;/li&gt;
&lt;li&gt;No Go Related:

&lt;ul&gt;
&lt;li&gt;​&lt;a href="https://preview.convertkit-mail2.com/click/dpheh0hzhm/aHR0cHM6Ly93d3cueW91dHViZS5jb20vd2F0Y2g_dj1fUTlPTE5pUVp4RQ==" rel="noopener noreferrer"&gt;How to find ANYTHING in Linux – newb guide&lt;/a&gt;
&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;/ul&gt;

&lt;h2&gt;
  
  
  🧭 Discoveries
&lt;/h2&gt;

&lt;p&gt;Here is the list of discovered interesting blog posts, videos, and projects that are worth checking out.&lt;/p&gt;

&lt;h3&gt;
  
  
  📝 Blog Posts
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;a href="https://bitfieldconsulting.com/posts/testing-errors" rel="noopener noreferrer"&gt;Testing errors in Go&lt;/a&gt; by John Arundel&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://www.willem.dev/articles/time-now-monotonic-clock/" rel="noopener noreferrer"&gt;time.Now() and the Monotonic Clock&lt;/a&gt;

&lt;ul&gt;
&lt;li&gt;The post discusses the use of &lt;code&gt;time.Now()&lt;/code&gt; in Go, particularly focusing on the monotonic clock feature. The author explains how Go ensures time consistency across operations, crucial for preventing errors in time-sensitive applications.&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;li&gt;&lt;a href="https://dev.to/aniket762/build-server-with-go-under-10-minutes-1i9m"&gt;Build Server With Go Under 10 minutes&lt;/a&gt;&lt;/li&gt;

&lt;li&gt;&lt;a href="https://www.whenmoon.xyz/posts/go-wallet-authentication-with-siwe-gin-and-jwt" rel="noopener noreferrer"&gt;Build a Go API with wallet authentication, JWT, Gin&lt;/a&gt;&lt;/li&gt;

&lt;/ul&gt;

&lt;h3&gt;
  
  
  📹 Videos
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://www.youtube.com/watch?v=NPq3d2HkxWU&amp;amp;list=PLCqcI2Ic-eM_RWwxxOvRBmt6jTNP8L5lP&amp;amp;index=119" rel="noopener noreferrer"&gt;Building a Chat with WebSockets and HTMX in Golang&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://www.youtube.com/watch?v=1ZbQS6pOlSQ&amp;amp;list=PLCqcI2Ic-eM_RWwxxOvRBmt6jTNP8L5lP&amp;amp;index=85" rel="noopener noreferrer"&gt;The BEST Tool to Structure Golang Projects&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://www.youtube.com/watch?v=zskPGr5dFU0&amp;amp;list=PLCqcI2Ic-eM_RWwxxOvRBmt6jTNP8L5lP&amp;amp;index=7" rel="noopener noreferrer"&gt;Pointers Are the Broccoli of Go -  Beth Knight  - July Gophers 2023&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://www.youtube.com/watch?v=Lv41EtkdZdU&amp;amp;list=PLCqcI2Ic-eM_RWwxxOvRBmt6jTNP8L5lP&amp;amp;index=8" rel="noopener noreferrer"&gt;Gosh - Writing Go at the Command Line - Nick Wells  - September Gophers&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  🛠️ Projects
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;a href="https://github.com/gookit/config" rel="noopener noreferrer"&gt;gookit/config&lt;/a&gt;

&lt;ul&gt;
&lt;li&gt;A comprehensive Go configuration management library that supports multiple file formats, environment variables, and command-line flags, offering flexibility in how configurations are loaded and merged.&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;li&gt;

&lt;a href="https://github.com/onsi/ginkgo" rel="noopener noreferrer"&gt;onsi/ginkgo&lt;/a&gt;

&lt;ul&gt;
&lt;li&gt;Ginkgo is a modern testing framework for Go, providing expressive syntax and powerful features for writing readable and maintainable tests, especially for behavior-driven development (BDD).&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;/ul&gt;




&lt;h1&gt;
  
  
  Daily Golang Issue #2 (2024-08-15)
&lt;/h1&gt;

&lt;h3&gt;
  
  
  Your daily hub for Go news, insights, and projects
&lt;/h3&gt;

&lt;h2&gt;
  
  
  ⚡️ Latest
&lt;/h2&gt;

&lt;p&gt;Here are the newest blog posts, videos, and projects from the Go community and all around it.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://tutorialedge.net/golang/go-123-iterators-tutorial" rel="noopener noreferrer"&gt;Go 1.23 Iterators Tutorial&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  🧭 Discoveries
&lt;/h2&gt;

&lt;p&gt;Here is the list of discovered interesting blog posts, videos, and projects that are worth checking out.&lt;/p&gt;

&lt;h3&gt;
  
  
  📝 Blog Posts
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;a href="https://bitfieldconsulting.com/posts/tdd-shameless-green" rel="noopener noreferrer"&gt;Shameless green: TDD in Go&lt;/a&gt; by John Arundel&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://appliedgo.net/bacalhau/" rel="noopener noreferrer"&gt;Distributed Computing With Dried, Salted Cod Fish, WASM, And (Tiny)Go&lt;/a&gt;

&lt;ul&gt;
&lt;li&gt;This post creatively explores the use of WebAssembly (WASM) and TinyGo for distributed computing, drawing an analogy to the historical use of dried cod fish for trade. The author discusses the benefits of using TinyGo for running Go code in constrained environments like WASM.&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;li&gt;

&lt;a href="https://rednafi.com/go/strategy_pattern/" rel="noopener noreferrer"&gt;Strategy pattern in Go&lt;/a&gt;

&lt;ul&gt;
&lt;li&gt;This article explains the Strategy Pattern, a behavioral design pattern that allows an algorithm's behavior to be selected at runtime. The author demonstrates how to implement this pattern in Go, making code more flexible and easier to maintain.&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;li&gt;&lt;a href="https://boyter.org/posts/how-to-start-go-project-2023/" rel="noopener noreferrer"&gt;How to start a Go project in 2023&lt;/a&gt;&lt;/li&gt;

&lt;/ul&gt;

&lt;h3&gt;
  
  
  📹 Videos
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://www.youtube.com/watch?v=B9uR2gLM80E&amp;amp;list=PLCqcI2Ic-eM_RWwxxOvRBmt6jTNP8L5lP&amp;amp;index=95" rel="noopener noreferrer"&gt;Go Concurrency Explained: Go Routines &amp;amp; Channels&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://www.youtube.com/watch?v=AcY_HID7mxY&amp;amp;list=PLCqcI2Ic-eM_RWwxxOvRBmt6jTNP8L5lP&amp;amp;index=65" rel="noopener noreferrer"&gt;How NOT to Write a Test in Go - Amir Malka&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://www.youtube.com/watch?v=YpRNFNFaLGY&amp;amp;list=PLCqcI2Ic-eM_RWwxxOvRBmt6jTNP8L5lP&amp;amp;index=21" rel="noopener noreferrer"&gt;Understanding the Go runtime - Jesus Espino&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://www.youtube.com/watch?v=egIDsv1RO88&amp;amp;list=PLCqcI2Ic-eM_RWwxxOvRBmt6jTNP8L5lP&amp;amp;index=181" rel="noopener noreferrer"&gt;How You Should Use Mutexes And Atomic Values In Golang?!&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  🛠️ Projects
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;a href="https://github.com/Evertras/bubble-table" rel="noopener noreferrer"&gt;Evertras/bubble-table&lt;/a&gt;

&lt;ul&gt;
&lt;li&gt;A customizable and interactive table component designed for the Bubble Tea framework, allowing developers to build rich terminal-based UIs.&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;li&gt;

&lt;a href="https://github.com/nanovms/ops" rel="noopener noreferrer"&gt;nanovms/ops&lt;/a&gt;

&lt;ul&gt;
&lt;li&gt;A tool for building and running unikernels in Go, designed to simplify the creation of lightweight, secure applications by bundling them into single-purpose virtual machines.&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;/ul&gt;




&lt;h1&gt;
  
  
  Daily Golang Issue #1 (2024-08-14)
&lt;/h1&gt;

&lt;h3&gt;
  
  
  Your daily hub for Go news, insights, and projects
&lt;/h3&gt;

&lt;h2&gt;
  
  
  ⚡️ Latest
&lt;/h2&gt;

&lt;p&gt;Here are the newest blog posts, videos, and projects from the Go community and all around it.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;​&lt;a href="https://preview.convertkit-mail2.com/click/dpheh0hzhm/aHR0cHM6Ly9nby5kZXYvYmxvZy9nbzEuMjM=" rel="noopener noreferrer"&gt;Go 1.23 is released&lt;/a&gt;​&lt;/li&gt;
&lt;li&gt;​&lt;a href="https://preview.convertkit-mail2.com/click/dpheh0hzhm/aHR0cHM6Ly93d3cueW91dHViZS5jb20vd2F0Y2g_dj1xZ3o3T042UXpQMA==" rel="noopener noreferrer"&gt;Changelog.com - Go Time #326 - Big shoes to fill&lt;/a&gt;​&lt;/li&gt;
&lt;li&gt;​&lt;a href="https://preview.convertkit-mail2.com/click/dpheh0hzhm/aHR0cHM6Ly93d3cuYnl0ZXNpemVnby5jb20vZ28tMS0yMy1pbi0yMy1taW51dGVz" rel="noopener noreferrer"&gt;Go 1.23 in 23 minutes (ByteSizeGo)&lt;/a&gt;​&lt;/li&gt;
&lt;li&gt;​&lt;a href="https://preview.convertkit-mail2.com/click/dpheh0hzhm/aHR0cHM6Ly91bnNraWxsZWQuYmxvZy9wb3N0cy9wcmVlbXB0aW9uLWluLWdvLWFuLWludHJvZHVjdGlvbi8_dXRtX3NvdXJjZT1wb2NrZXRfc2hhcmVk" rel="noopener noreferrer"&gt;Preemption in Go: an introduction&lt;/a&gt;​&lt;/li&gt;
&lt;li&gt;📹 &lt;a href="https://preview.convertkit-mail2.com/click/dpheh0hzhm/aHR0cHM6Ly93d3cueW91dHViZS5jb20vd2F0Y2g_dj0wSmlUMDN1d0FjMA==" rel="noopener noreferrer"&gt;Starting new series | Let’s learn - Go language - 1&lt;/a&gt;​&lt;/li&gt;
&lt;li&gt;No related to Go

&lt;ul&gt;
&lt;li&gt;​&lt;a href="https://preview.convertkit-mail2.com/click/dpheh0hzhm/aHR0cHM6Ly9hbGV4cGxlc2Nhbi5jb20vcG9zdHMvMjAyNC8wOC8xMC93ZXp0ZXJtLz91dG1fc291cmNlPXBvY2tldF9zaGFyZWQ=" rel="noopener noreferrer"&gt;Okay, I really like WezTerm&lt;/a&gt;
&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;/ul&gt;

&lt;h2&gt;
  
  
  🧭 Discoveries
&lt;/h2&gt;

&lt;p&gt;Here is the list of discovered interesting blog posts, videos, and projects that are worth checking out.&lt;/p&gt;

&lt;h3&gt;
  
  
  📝 Blog Posts
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;a href="https://bitfieldconsulting.com/posts/functional" rel="noopener noreferrer"&gt;Functional programming in Go&lt;/a&gt; by John Arundel&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://www.calhoun.io/connecting-to-a-postgresql-database-with-gos-database-sql-package/" rel="noopener noreferrer"&gt;Connecting to a PostgreSQL database with Go's database/sql package&lt;/a&gt;

&lt;ul&gt;
&lt;li&gt;A comprehensive guide on connecting to a PostgreSQL database using Go’s &lt;code&gt;database/sql&lt;/code&gt; package. The post walks you through the steps to set up a connection, execute queries, and handle errors.&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;li&gt;

&lt;a href="https://benhoyt.com/writings/go-1brc/" rel="noopener noreferrer"&gt;The One Billion Row Challenge in Go: from 1m45s to 3.4s in nine solutions&lt;/a&gt;

&lt;ul&gt;
&lt;li&gt;The author discusses optimizing a Go program to handle one billion rows of data. The post details different strategies and solutions implemented to significantly reduce processing time, offering insights into performance tuning in Go.&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;li&gt;

&lt;a href="https://www.willem.dev/articles/how-to-parse-time-date/" rel="noopener noreferrer"&gt;How to parse a time or date in Go&lt;/a&gt;

&lt;ul&gt;
&lt;li&gt;This article explains how to parse and format time and date strings in Go, covering common use cases and potential pitfalls. The author provides code examples to demonstrate how to handle various date and time formats effectively.&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;/ul&gt;

&lt;h3&gt;
  
  
  📹 Videos
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;a href="https://www.youtube.com/watch?v=LP0sTNruvaM&amp;amp;list=PLCqcI2Ic-eM_RWwxxOvRBmt6jTNP8L5lP" rel="noopener noreferrer"&gt;How to Rewrite a Service - Michal Bock - April Gophers 2023&lt;/a&gt; &lt;/li&gt;
&lt;li&gt;&lt;a href="https://www.youtube.com/watch?v=sRIFJ6H6Nmg&amp;amp;list=PLCqcI2Ic-eM_RWwxxOvRBmt6jTNP8L5lP&amp;amp;index=10" rel="noopener noreferrer"&gt;Time to Reflect - Sam Williams  - September Gophers&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://www.youtube.com/watch?v=ICSMdZO9Gns&amp;amp;list=PLCqcI2Ic-eM_RWwxxOvRBmt6jTNP8L5lP&amp;amp;index=98" rel="noopener noreferrer"&gt;Using RabbitMQ Steams In Go&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://www.youtube.com/watch?v=EkK8Jxjj95s&amp;amp;list=PLCqcI2Ic-eM_RWwxxOvRBmt6jTNP8L5lP&amp;amp;index=69" rel="noopener noreferrer"&gt;Understanding Language Server Protocol - autocomplete, formatting - Adrian Hesketh&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  🛠️ Projects
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;a href="https://github.com/knadh/koanf" rel="noopener noreferrer"&gt;knadh/koanf&lt;/a&gt;

&lt;ul&gt;
&lt;li&gt;A simple, lightweight, and extensible Go configuration management library, supporting JSON, TOML, YAML, and more. It allows easy merging and layering of configurations from various sources.&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;li&gt;

&lt;a href="https://github.com/adrg/xdg" rel="noopener noreferrer"&gt;adrg/xdg&lt;/a&gt;

&lt;ul&gt;
&lt;li&gt;A Go implementation of the XDG Base Directory Specification, providing a standardized way to manage user directories and application data locations across different operating systems.&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;/ul&gt;




</description>
      <category>go</category>
    </item>
    <item>
      <title>Full Introduction to Golang with Test-Driven Development. Part I</title>
      <dc:creator>Max Kovalevsky</dc:creator>
      <pubDate>Sun, 28 Jul 2024 15:52:42 +0000</pubDate>
      <link>https://dev.to/kovalevsky/full-introduction-to-golang-with-test-driven-development-part-i-12ni</link>
      <guid>https://dev.to/kovalevsky/full-introduction-to-golang-with-test-driven-development-part-i-12ni</guid>
      <description>&lt;blockquote&gt;
&lt;p&gt;This is a post based on the script for my video &lt;a href="https://www.youtube.com/watch?v=EECXgocw4N0&amp;amp;t=487s" rel="noopener noreferrer"&gt;"A new learning way on how to write "Hello, World!" program in Go"&lt;/a&gt; which available &lt;a href="https://www.youtube.com/channel/UCvjx6Q_8iyME0FHiDB-nxiA" rel="noopener noreferrer"&gt;"on my YouTube channel"&lt;/a&gt; and it is a part of the upcoming course "Grokking Go Fundamentals with Tests" (GGFT).&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Hello and welcome. In this chapter, we will write our first &lt;a href="https://kovalevsky.io/golang/" rel="noopener noreferrer"&gt;Go&lt;/a&gt; program. As a tradition, we will create a classic "hello world" program. It is a program that prints "Hello, World!" in the terminal after you run it. In this series, we'll do all examples in the &lt;a href="https://kovalevsky.io/test-driven-development/" rel="noopener noreferrer"&gt;TDD&lt;/a&gt; way. &lt;a href="https://kovalevsky.io/test-driven-development/" rel="noopener noreferrer"&gt;TDD (test-driven development)&lt;/a&gt; is a special way of writing software. That special way of writing software is based on the Test-driven development cycle. &lt;/p&gt;

&lt;p&gt;The Test-driven development cycle consists of the following steps: &lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Add a test, which means you have to write tests first for the code that solves your problem. &lt;/li&gt;
&lt;li&gt;Run tests. All new tests must be failed because you don't have enough code that passes these tests. &lt;/li&gt;
&lt;li&gt;Write the simplest code that passes the new test. &lt;/li&gt;
&lt;li&gt;All tests now should be passed. &lt;/li&gt;
&lt;li&gt;Refactor as needed, using tests after each refactor to ensure that functionality is preserved. &lt;/li&gt;
&lt;li&gt;Repeat the cycle. So, for our first and all future examples, we're gonna follow the TDD way in general and TDD cycle in particular. &lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;I found tests quite useful in daily programming practice but also it's a very practical way to learn a new programming language.&lt;/p&gt;

&lt;p&gt;So first of all, we need to create a folder for our project. In this series, all our examples will be in one folder. Let's call it "go-sandbox," but you can name it whatever you want. I decided to name it "sandbox" because it will be a folder with a bunch of small examples that are mostly not related to each other; it will be basically a sandbox for our experiments with &lt;a href="https://kovalevsky.io/golang/" rel="noopener noreferrer"&gt;Go&lt;/a&gt;. I will create a folder using a Terminal emulator. You can use any terminal emulator app, for example, you can use one of the most popular terminal emulators on macOS that's called iTerm 2. In the Terminal, open the path where you're gonna create a folder for the project using the command &lt;code&gt;cd&lt;/code&gt;.&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;projects/personal
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now I'm in the folder with all my personal projects, I'm gonna create a folder called "go-sandbox" using the command &lt;code&gt;mkdir&lt;/code&gt;.&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;go-sandbox
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Open this folder in the terminal using the &lt;code&gt;cd&lt;/code&gt; command again. We will need the terminal with this opened folder later. After creating a folder open it in your editor or IDE of choice. I use different editors and IDEs for writing Go code such as Goland, VSCode, and &lt;a href="https://kovalevsky.io/neovim/" rel="noopener noreferrer"&gt;Neovim&lt;/a&gt; but now I will open it inside Neovim. Once we opened the project folder in our editor, we need to talk about Go program structure. First of all, all Go projects must have a "go.mod" file where you define information about your module, such as the module's path, the minimum version of Go that uses this module, information about dependencies on other modules, etc.&lt;/p&gt;

&lt;p&gt;But what is the module? Go code is organized into modules and packages. Basically, every Go program or project is a module. It should have a unique identifier, a path, which could be a location from which you can download this module. A module can be distributed as a dependency for another module. So, if you don't have a "go.mod" file in your project you need to use Go tool command &lt;code&gt;go mod&lt;/code&gt; to create it or you can create it manually. Let's go back to the terminal and open the project's folder again. Type command &lt;code&gt;go mod init &amp;lt;module_name&amp;gt;&lt;/code&gt; which in our case is &lt;code&gt;go mod init go-sandbox&lt;/code&gt;. You will see that file "go.mod" appeared in the folder.&lt;/p&gt;

&lt;p&gt;Now, let's follow our TDD cycle and do the first step. The first step of the test-driven development cycle is to add a test. But in the first example, let's start with creating a file that will contain the simplified version of the code for which we'll add a test. We're doing it first just to have some basic understanding of how Go code looks like. So first of all, let's start with creating a new folder for our package "helloworld" in the root of the project folder.&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;helloworld
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Open the new folder in the terminal.&lt;/p&gt;

&lt;p&gt;There, inside the folder, create a file called "helloworld.go" by using the command "touch," but you can create it inside your code editor.&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;helloworld.go
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Open the file in your code editor. Our Go file was created and it's empty for now. Just follow me and write the first line in the file.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight go"&gt;&lt;code&gt;&lt;span class="k"&gt;package&lt;/span&gt; &lt;span class="n"&gt;helloworld&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The very first line says package helloworld and that line is "package declaration." "Package declaration" always begins with the keyword "package" and must be in every Go file, and it specifies to which package file belongs to. But what is a package? Go programs are structured into packages - some kind of grouping units which Go program consist of. And as I mentioned before, every module has at least one package. We will talk about packages in future chapters.&lt;/p&gt;

&lt;p&gt;Okay, we have our first Go file "helloworld.go"; so what's next? In most programming languages, the program "Hello, World!" contains a few lines of code where you call some method with the string "Hello, World!" as the first argument of this method. When you run the program, this method prints the string in the terminal. Since we're following the test-driven development way, we need to write a test that checks that our code works correctly and prints a string "Hello, World!" But we are not going to check the method that prints the string in the terminal. It requires a bit more knowledge for the first lesson. Instead, we're gonna write a simple function called "HelloWorld" that returns the string "Hello, World!".&lt;/p&gt;

&lt;p&gt;If you had an experience with other programming languages before you probably know what a function is. But if not, here is a simple explanation of what a function is and what it is used for: a function is a named block of code that performs a specific task. It is like a mini-program within your program that you can call and use multiple times. &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;A function has a name that you choose to describe what it does. In our case, its name is "HelloWorld". &lt;/li&gt;
&lt;li&gt;It can take inputs or parameters (if needed) to perform its task. Our function "HelloWorld" won't have any parameters. &lt;/li&gt;
&lt;li&gt;It can also return a result (if needed) after completing its task. As I mentioned before, our function must return a string "Hello, World!" &lt;/li&gt;
&lt;li&gt;Inside the function, you write the code that defines the task or actions it should perform.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;For the function HelloWorld, we'll write a test that checks the function returns the expected value. And then in our main file of the program, we will call the function "HelloWorld" to pass the result of calling this function to the method that prints the string in the terminal. Okay, now let's start to write function HelloWorld. To write a function in Go you need to use the keyword "func".&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight go"&gt;&lt;code&gt;&lt;span class="k"&gt;func&lt;/span&gt; &lt;span class="n"&gt;HelloWorld&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;

&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This function doesn't return any values and doesn't have any logic inside for now. However, if we still follow the test-driven development cycle, we have to write the code inside the function on step 3. &lt;/p&gt;

&lt;p&gt;So let's go back to step 1 and add a test for the function HelloWorld. In the folder of the package "helloworld," create the file called "helloworld_test.go." There are some naming rules for tests. Any test files that will be run by Go's built-in test runner must be named as "xxx_test.go" where "xxx" is the name of the file that contains the code which tests are written for. In our case, we're gonna write tests for the code inside the file called "helloworld.go," so we need to name our test file "helloworld_test.go." &lt;/p&gt;

&lt;p&gt;In Go, to test some function, you need to write another function, a test function, inside a test file. This test function should contain checking of the function that we want to test. In our case, in the test function, we need to check that function HelloWorld returns the string "Hello, World!" So first of all, we need to write a function called "TestHelloWorld".&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight go"&gt;&lt;code&gt;&lt;span class="k"&gt;func&lt;/span&gt; &lt;span class="n"&gt;TestHelloWorld&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;

&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The name "TestHelloWorld" is very important here. There is a convention for naming a test function which looks like "TestXxx" where "Xxx" is the name of the function that we want to test, which is HelloWorld. &lt;/p&gt;

&lt;p&gt;Okay, so now we need to write a checking that function HelloWorld returns a string "Hello, World!". To check the result of executing the function, we need to save this result somewhere first. We can use a variable to save the result of executing a function.&lt;/p&gt;

&lt;p&gt;A variable is a named container that holds a value. It's like a labeled box that can store different types of information, such as numbers, text, or more complex data. &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;A variable has a name that you choose to identify it. In our case, the name is "got." &lt;/li&gt;
&lt;li&gt;It can hold different types of values, such as numbers, strings, or booleans. Since the function "HelloWorld" returns a string, the variable "got" also should have a string type. &lt;/li&gt;
&lt;li&gt;You can assign a value to a variable using the "=" operator. Once a value is assigned, you can change it or use it in your program. &lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;There are several ways of declaring a variable in Go, but now we're gonna use the shortest one. It's called short variable declaration and it uses a special operator :=. The "short variable declaration" combines declaration and assignment of the variable. That means that you declare a type of the variable and also store some value in the variable.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;someVariable := someValue
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In our test function, we're gonna create a variable called "got":&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight go"&gt;&lt;code&gt;&lt;span class="k"&gt;func&lt;/span&gt; &lt;span class="n"&gt;TestHelloWorld&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="n"&gt;got&lt;/span&gt; &lt;span class="o"&gt;:=&lt;/span&gt; &lt;span class="n"&gt;HelloWorld&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;The line "HelloWorld()" means that we're calling the function HelloWorld() and it should return some value, and that value should be stored in a variable "got." Now let's declare another variable called "want."&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight go"&gt;&lt;code&gt;&lt;span class="k"&gt;func&lt;/span&gt; &lt;span class="n"&gt;TestHelloWorld&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="n"&gt;got&lt;/span&gt; &lt;span class="o"&gt;:=&lt;/span&gt; &lt;span class="n"&gt;HelloWorld&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
    &lt;span class="n"&gt;want&lt;/span&gt; &lt;span class="o"&gt;:=&lt;/span&gt; &lt;span class="s"&gt;"Hello, World!"&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;We just created a new variable called "want" and stored a value there, which is a string "Hello, World!" We're gonna use this variable to compare it with the variable "got," and that's how we will check that function HelloWorld returns the correct value. &lt;/p&gt;

&lt;p&gt;Let's use an "if statement" to compare variables.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight go"&gt;&lt;code&gt;&lt;span class="k"&gt;func&lt;/span&gt; &lt;span class="n"&gt;TestHelloWorld&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="n"&gt;got&lt;/span&gt; &lt;span class="o"&gt;:=&lt;/span&gt; &lt;span class="n"&gt;HelloWorld&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
    &lt;span class="n"&gt;want&lt;/span&gt; &lt;span class="o"&gt;:=&lt;/span&gt; &lt;span class="s"&gt;"Hello, World!"&lt;/span&gt;

    &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;expected&lt;/span&gt; &lt;span class="o"&gt;!=&lt;/span&gt; &lt;span class="n"&gt;got&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;

    &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The "if statement" in Go is pretty much the same as the if statement in another programming language. It is used to make decisions based on a condition. It checks if something is true or false and executes different code depending on the result. &lt;/p&gt;

&lt;p&gt;Here is a simplified algorithm for working with an "if statement": &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;You use the keyword "if" followed by a condition in parentheses. &lt;/li&gt;
&lt;li&gt;If the condition is true, the code inside the "if" block is executed. &lt;/li&gt;
&lt;li&gt;If the condition is false, the code inside the "if" block is skipped. &lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;We use the "inequality operator" (!=) to check if the variable "want" and "got" have different values. &lt;/p&gt;

&lt;p&gt;Okay, so what are we gonna do if variables will have different values? We need to show a message that this test failed. This message will be printed in the terminal where we will run tests for our Go program. &lt;/p&gt;

&lt;p&gt;To show the message about the failed test, we need to use special methods that can be provided to us by Go's built-in testing framework. We can have access to Go's built-in testing framework's methods in each test function. All we need to do is just specify a parameter of the test function. So let's do it. In the function TestHelloWorld, we're gonna specify the parameter called "t," which has a special type, which is actually a struct. But don't focus too much on that now, we'll talk about this later.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight go"&gt;&lt;code&gt;&lt;span class="k"&gt;func&lt;/span&gt; &lt;span class="n"&gt;TestHelloWorld&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;t&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="n"&gt;testing&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;T&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="n"&gt;got&lt;/span&gt; &lt;span class="o"&gt;:=&lt;/span&gt; &lt;span class="n"&gt;HelloWorld&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
    &lt;span class="n"&gt;want&lt;/span&gt; &lt;span class="o"&gt;:=&lt;/span&gt; &lt;span class="s"&gt;"Hello, World!"&lt;/span&gt;

    &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;want&lt;/span&gt; &lt;span class="o"&gt;!=&lt;/span&gt; &lt;span class="n"&gt;got&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;

    &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;All we need to know is that parameter "t" includes all methods of Go's built-in test framework that we need. The parameter "t" has type (capital) "T," and that capital T type is provided by the testing package. That's why we write "testing.T," not just capital T. So basically, we have a package called "testing" which is Go's built-in package. &lt;/p&gt;

&lt;p&gt;However, to use type T from the package "testing," we need to be sure that we have access to things from package "testing" in OUR source file. For that, we need to import package "testing" in this file. In the beginning of the file, right below the package declaration, write a new line import "testing".&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight go"&gt;&lt;code&gt;&lt;span class="k"&gt;package&lt;/span&gt; &lt;span class="n"&gt;helloworld&lt;/span&gt;

&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="s"&gt;"testing"&lt;/span&gt;

&lt;span class="c"&gt;// ...&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now, inside the if statement body, let's call a method that will show a message that the test failed.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight go"&gt;&lt;code&gt;    &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;want&lt;/span&gt; &lt;span class="o"&gt;!=&lt;/span&gt; &lt;span class="n"&gt;got&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="n"&gt;t&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Errorf&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"Failed! Expected %q but received %q"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;want&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;got&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;We're using the method called "Errorf," and it takes the string as the first parameter. This string will be printed as a message that the test failed. You may notice that the string contains some special characters %q. The thing is that the method Errorf replaces all %q substrings by values from parameters after the first one. But there are plenty of combinations of substrings that begin with %q, and they all have their special meaning. All substrings that begin with % are called formatting verbs in Go. In this case, the formatting verb %q means that the value from the second parameter will be wrapped into double quotes and then inserted into the string from the first parameter. &lt;/p&gt;

&lt;p&gt;Okay, we finished with our first test, and it means that we've done the first step in the Test-driven development cycle. Now it's time to make step 2 - run the test. To run the test, we're gonna use the go tool. &lt;/p&gt;

&lt;p&gt;Open the terminal in the project folder. Now, in the terminal, type the command go test. It will show you the message:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;❯ go test 
# hello-world [hello-world.test]
./hello_test.go:6:12: HelloWorld() (no value) used as value
FAIL    hello-world [build failed]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;It says that the function that we're checking and calling inside the test does not return any values. And now we passed step 2 in our test-driven development cycle. Now it's time to do step 3 and write the simplest code that will pass our test. Open the file "helloworld.go" and go to the function declaration. Write type 'string' after paired parentheses.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight go"&gt;&lt;code&gt;&lt;span class="k"&gt;func&lt;/span&gt; &lt;span class="n"&gt;HelloWorld&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="kt"&gt;string&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;Now Go is expecting that function HelloWorld returns a string value. However, we didn't write the code that returns any values from HelloWorld, and that's why your IDE will probably show you some signs that something is wrong. Okay, now let's write this line which means that function HelloWorld returns a string.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight go"&gt;&lt;code&gt;&lt;span class="k"&gt;func&lt;/span&gt; &lt;span class="n"&gt;HelloWorld&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="kt"&gt;string&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="s"&gt;""&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Let's run the test again (&lt;code&gt;go test&lt;/code&gt;). Okay, we did enough to call our function inside the test properly, and finally, we see that our test case failed.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;❯ go &lt;span class="nb"&gt;test&lt;/span&gt; 
&lt;span class="nt"&gt;---&lt;/span&gt; FAIL: TestHelloWorld &lt;span class="o"&gt;(&lt;/span&gt;0.00s&lt;span class="o"&gt;)&lt;/span&gt;
    hello_test.go:10: Failed! Expected &lt;span class="s2"&gt;"Hello, World!"&lt;/span&gt; but received &lt;span class="s2"&gt;""&lt;/span&gt;
FAIL
&lt;span class="nb"&gt;exit &lt;/span&gt;status 1
FAIL    hello-world     0.624s
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;That's alright. We just need to make sure that our test works correctly. Now it's time to write the code inside HelloWorld to pass the test.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight go"&gt;&lt;code&gt;&lt;span class="k"&gt;func&lt;/span&gt; &lt;span class="n"&gt;HelloWorld&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="kt"&gt;string&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="s"&gt;"Hello, World!"&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Great! There are not many things to refactor, so we can skip step 5. We successfully finished our test-development cycle, and now let's complete our program so that it will print the string "Hello, World!" in the terminal. &lt;/p&gt;

&lt;p&gt;We need to run our program, and for that, we can use a special command provided by go tool. But it's not gonna work for several reasons. First of all, we didn't call our HelloWorld anywhere and didn't use the method that prints the string in the terminal.&lt;br&gt;
But where do we need to write this code? We cannot just call the function inside the file we want, like in programming languages such as JavaScript or Python. In Go, we need to have a function called "main," which is an entry point to our program. This function will be called first when we run our program. Let's write this function in the file "hello.go".&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight go"&gt;&lt;code&gt;&lt;span class="k"&gt;func&lt;/span&gt; &lt;span class="n"&gt;main&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;

&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now we need to use some method that will print the string in the terminal. Go has a built-in package called "fmt," which stands for formatting. The package "fmt" has a bunch of methods for formatting and printing strings. The method that we need is called "Println," so let's use it in our code.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight go"&gt;&lt;code&gt;&lt;span class="k"&gt;func&lt;/span&gt; &lt;span class="n"&gt;main&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="n"&gt;fmt&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Println&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;HelloWorld&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;Don't forget about the import of the package which method you're gonna use in your code.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight go"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="s"&gt;"fmt"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The method Println takes the string as the first argument and prints it in the terminal. But it also prints a string on a newline. That's what the 'ln' in the name of the method stands for. &lt;/p&gt;

&lt;p&gt;Okay, now it's time to run our program. Open the terminal in the root of the project's folder and type go run hello.go. It will show you the message:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;❯ go run hello.go 
package command-line-arguments is not a main package
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Well, the thing is that every Go program should also have a main package the same way as the main function. So the main package is an entry point in a Go program. When you run a Go program by command go run, it will look at the package "main" first and will execute the function main inside that package. Remember that we declared that our package name is "hello" in hello.go and hello_test.go files. So all we need to do is just to create a file called "main.go" in the root of the project folder.&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; ..
&lt;span class="nb"&gt;touch &lt;/span&gt;main.go
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Inside the new file write the package declaration line.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight go"&gt;&lt;code&gt;&lt;span class="k"&gt;package&lt;/span&gt; &lt;span class="n"&gt;main&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;And move the function "main" from the file helloworld.go to main.go.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight go"&gt;&lt;code&gt;&lt;span class="k"&gt;package&lt;/span&gt; &lt;span class="n"&gt;main&lt;/span&gt;

&lt;span class="k"&gt;func&lt;/span&gt; &lt;span class="n"&gt;main&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="n"&gt;fmt&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Println&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;HelloWorld&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;Since we are using the function HelloWorld from the package "helloworld," we need to import this package in the file main.go; also, don't forget about importing the package "fmt."&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight go"&gt;&lt;code&gt;&lt;span class="k"&gt;package&lt;/span&gt; &lt;span class="n"&gt;main&lt;/span&gt;

&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="s"&gt;"fmt"&lt;/span&gt;
    &lt;span class="s"&gt;"go-sandbox/helloworld"&lt;/span&gt;
&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="k"&gt;func&lt;/span&gt; &lt;span class="n"&gt;main&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="n"&gt;fmt&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Println&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;HelloWorld&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;But this is still not enough for this code to work. In Go, if you use some function from another package, you need to write the package's name before the name of the function on the line where you call it; like that:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight go"&gt;&lt;code&gt;    &lt;span class="n"&gt;fmt&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Println&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;helloworld&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;HelloWorld&lt;/span&gt;&lt;span class="p"&gt;())&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Final code:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight go"&gt;&lt;code&gt;&lt;span class="k"&gt;package&lt;/span&gt; &lt;span class="n"&gt;main&lt;/span&gt;

&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="s"&gt;"fmt"&lt;/span&gt;
    &lt;span class="s"&gt;"go-sandbox/helloworld"&lt;/span&gt;
&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="k"&gt;func&lt;/span&gt; &lt;span class="n"&gt;main&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="n"&gt;fmt&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Println&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;helloworld&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;HelloWorld&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;Let's try to run our program again, but this time you need to run the file main.go in the project root folder instead of helloworld.go in the helloworld package folder.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;go run main.go
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This should work perfectly. You can also run it by using go run . instead of writing the file name properly since it will look at package main first anyway.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;go run &lt;span class="nb"&gt;.&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The full source code is available on GitHub repository &lt;a href="https://github.com/kovalevsky0/ggft" rel="noopener noreferrer"&gt;GGFT&lt;/a&gt;.&lt;/p&gt;

</description>
      <category>go</category>
      <category>tdd</category>
      <category>testing</category>
    </item>
    <item>
      <title>A new learning way on how to write "Hello, World!" program in Go [video]</title>
      <dc:creator>Max Kovalevsky</dc:creator>
      <pubDate>Thu, 29 Feb 2024 16:01:19 +0000</pubDate>
      <link>https://dev.to/kovalevsky/a-new-learning-way-on-how-to-write-hello-world-program-in-go-5f7b</link>
      <guid>https://dev.to/kovalevsky/a-new-learning-way-on-how-to-write-hello-world-program-in-go-5f7b</guid>
      <description>&lt;p&gt;Hello DEV Community!&lt;/p&gt;

&lt;p&gt;I want to share with you my first video in the series about Go programming language. This video is a part of my upcoming course "Grokking Go Fundamentals with Tests" (GGFT) so if you are interested in learning Go with tests and TDD way subscribe to my channel to ensure you don't miss my next videos in the series.&lt;/p&gt;

&lt;p&gt;In this video we will write a classic "Hello, World!" program but following Test-driven development way. If you don't know what is TDD you can watch this video where I introduce to this technique. &lt;/p&gt;

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

&lt;p&gt;&lt;a href="https://www.youtube.com/watch?v=EECXgocw4N0" rel="noopener noreferrer"&gt;Link to the video&lt;/a&gt;&lt;/p&gt;

</description>
      <category>go</category>
      <category>programming</category>
      <category>testing</category>
      <category>development</category>
    </item>
    <item>
      <title>#1 Weekly Dose Of Software Engineering Stuff</title>
      <dc:creator>Max Kovalevsky</dc:creator>
      <pubDate>Fri, 30 Jul 2021 14:41:13 +0000</pubDate>
      <link>https://dev.to/kovalevsky/1-weekly-dose-of-software-engineering-stuff-910</link>
      <guid>https://dev.to/kovalevsky/1-weekly-dose-of-software-engineering-stuff-910</guid>
      <description>&lt;blockquote&gt;
&lt;p&gt;‚ùóÔ∏èüíå  This post is a public version of the newsletter edition that was published 2 days ago. Sign up to &lt;a href="https://byte.ski/newsletter" rel="noopener noreferrer"&gt;&lt;strong&gt;Weekly Dose Of Software Engineering Stuff&lt;/strong&gt;&lt;/a&gt; to be among the first to receive the newsletter.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Hello there! üëã&lt;/p&gt;

&lt;p&gt;It's the first edition of &lt;strong&gt;Weekly Dose Of Software Engineering Stuff&lt;/strong&gt; - a newsletter where you can read the content of topics that might be interesting for software developers and engineers.&lt;/p&gt;

&lt;p&gt;The goal of this newsletter is to share resources from my blog and the Internet that are related to topics that I found interesting as a software developer. The content related to TypeScript, Node, programming languages in general, testing for devs, writing and note-taking, useful resources about computer science, algorithms and data structures, interview preparation, software architecture, books, DevOps, and many many other interesting things.&lt;/p&gt;

&lt;p&gt;As you may have noticed, the name of the newsletter was inspired by one popular YouTube channel. But I think it's quite original üôÇ.&lt;/p&gt;

&lt;p&gt;Short information about me. I am a software developer currently based in Prague. I work with technologies like TypeScript, React, Node, and others. The project that I'm working on with a team is a solution for cloud backups (AWS, Google Cloud, etc). So, content related to cloud computing can also be in the future.&lt;/p&gt;

&lt;p&gt;Since you already subscribed to my newsletter you know that I have a &lt;a href="https://byte.ski" rel="noopener noreferrer"&gt;blog&lt;/a&gt;. Now it's mostly about TypeScript and Node but I have plans to expand a list of content topics. Stay tuned!&lt;/p&gt;

&lt;p&gt;Another one of my activities is &lt;a href="https://byte.ski/typescript-book" rel="noopener noreferrer"&gt;a book about TypeScript&lt;/a&gt; which is available for free as &lt;a href="https://byte.ski/tags/typescriptbook" rel="noopener noreferrer"&gt;series of posts on my blog&lt;/a&gt; and PDF eBook. In this letter, you can find a link to the latest version of the eBook üìö.&lt;/p&gt;

&lt;h2&gt;
  
  
  Blog
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;About a week ago I published the post &lt;a href="https://byte.ski/blog/article/what-is-strict-mode-in-typescript-and-why-and-when-you-should-use-it" rel="noopener noreferrer"&gt;What Is Strict Mode In TypeScript, Why And When You Should Use It?&lt;/a&gt;. It's more theoretical material for ones who are just starting out to work with TypeScript and don't know what TypeScript's strict "mode". I have a draft of another post about strict options in TypeScript that described it in a more practical way. I'm going to publish it soon.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Resources from the Internet
&lt;/h2&gt;

&lt;h3&gt;
  
  
  TypeScript
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;a href="https://tsconf.io" rel="noopener noreferrer"&gt;TSConf 2021&lt;/a&gt; is coming and conference's team announces list of &lt;a href="https://tsconf.io/speakers" rel="noopener noreferrer"&gt;speakers&lt;/a&gt;, &lt;a href="https://tsconf.io/sponsors" rel="noopener noreferrer"&gt;sponsors&lt;/a&gt;, and more details about &lt;a href="https://tsconf.io/schedule" rel="noopener noreferrer"&gt;schedule&lt;/a&gt;

&lt;ul&gt;
&lt;li&gt;The conference will be on &lt;strong&gt;September 10 in online&lt;/strong&gt;
&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;li&gt;

&lt;a href="https://www.reddit.com/r/dataisbeautiful/comments/om66b5/oc_most_popular_programming_languages_according/" rel="noopener noreferrer"&gt;Most Popular Programming Languages, according to public GitHub Repositories (Jun 2021)&lt;/a&gt;

&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;TypeScript: 7.2%&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;JavaScript: 19.0%&lt;/li&gt;
&lt;li&gt;Python: 16.4%&lt;/li&gt;
&lt;li&gt;Java: 12.8%&lt;/li&gt;
&lt;li&gt;Go: 7.6%&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;li&gt;

&lt;a href="https://twitter.com/rauschma" rel="noopener noreferrer"&gt;Dr. Axel Rauschmayer&lt;/a&gt; published the article &lt;a href="https://2ality.com/2021/07/simple-monorepos.html" rel="noopener noreferrer"&gt;Simple monorepos via npm workspaces and TypeScript project references&lt;/a&gt;
&lt;/li&gt;

&lt;/ul&gt;

&lt;h3&gt;
  
  
  Node
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;The recordings of Node.js team's weekly meetings were posted on official Node.js YouTube channel 

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://www.youtube.com/watch?v=4ngcDx346II" rel="noopener noreferrer"&gt;Node-API Team Meeting (2021-07-23)&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://www.youtube.com/watch?v=YOTlQHjtff0" rel="noopener noreferrer"&gt;Node.js Loaders team Meeting (2021-07-23)&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://www.youtube.com/watch?v=jhi79fPZINY" rel="noopener noreferrer"&gt;Node.js Tooling Group Meeting (2021-07-23)&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;li&gt;&lt;a href="https://www.nearform.com/blog/using-abortsignal-in-node-js/?utm_source=ESnextNews.com&amp;amp;utm_medium=Weekly+Newsletter&amp;amp;utm_campaign=2021-07-27" rel="noopener noreferrer"&gt;Using AbortSignal in Node.js (NearForm Blog)&lt;/a&gt;&lt;/li&gt;

&lt;/ul&gt;

&lt;h4&gt;
  
  
  NestJS
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://trilon.io/blog/announcing-nestjs-8-whats-new" rel="noopener noreferrer"&gt;Announcing NestJS 8: What‚Äôs New? (Trilon Blog)&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  JavaScript
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://dev.to/arcanis/yarn-3-0-performances-esbuild-better-patches-e07"&gt;Yarn 3.0 üöÄü§ñ Performances, ESBuild, Better Patches, ... (dev.to)&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  React
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;[React Labs: React 18 Working Group Q&amp;amp;A &lt;a href="https://dev.toYouTube"&gt;Audio&lt;/a&gt;](&lt;a href="https://www.youtube.com/watch?v=F4YjkMqTgao" rel="noopener noreferrer"&gt;https://www.youtube.com/watch?v=F4YjkMqTgao&lt;/a&gt;)&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Visual Studio Code
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;a href="https://marketplace.visualstudio.com/items?itemName=ms-vscode.vscode-typescript-next" rel="noopener noreferrer"&gt;JavaScript and TypeScript Nightly Extension (marketplace.visualstudio.com)&lt;/a&gt;

&lt;ul&gt;
&lt;li&gt;VS Code extension that enables the nightly build of TypeScript (typescript@next) as VS Code's built-in TypeScript version used to power JavaScript and TypeScript IntelliSense.&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;li&gt;&lt;a href="https://code.visualstudio.com/updates/v1_58" rel="noopener noreferrer"&gt;Visual Studio Code June 2021 (code.visualstudio.com)&lt;/a&gt;&lt;/li&gt;

&lt;/ul&gt;

&lt;h3&gt;
  
  
  Web
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Interesting post &lt;a href="https://www.hazem.cool/blog/the-future-of-the-web" rel="noopener noreferrer"&gt;The Future Of The Web&lt;/a&gt; by HazemOsama&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Videos
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://www.youtube.com/playlist?list=PLn2e1F9Rfr6kDUi_QRRUBurbPKU0Qr_to" rel="noopener noreferrer"&gt;Prisma Day 2021 Workshops (YouTube Playlist)&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Vim
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;I don't use vim as much as I used before, but I'm still interested in this. Here is a &lt;a href="https://changelog.com/podcast/450" rel="noopener noreferrer"&gt;special episode of Changelog podcast fully about vim&lt;/a&gt; with great hosts and guests&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Obsidian
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;I use &lt;a href="https://byte.ski/notes/Obsidian" rel="noopener noreferrer"&gt;Obsidian&lt;/a&gt; every day for note-taking, writing blog posts, and even for this newsletter.

&lt;ul&gt;
&lt;li&gt;
&lt;a href="https://twitter.com/tallguyjenks" rel="noopener noreferrer"&gt;Bryan Jenks&lt;/a&gt; published &lt;a href="https://www.youtube.com/watch?app=desktop&amp;amp;v=wB89lJs5A3s&amp;amp;t=4612s" rel="noopener noreferrer"&gt;a huge video workshop&lt;/a&gt; about his Obsidian Zettelkasten Workflow&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;/ul&gt;

&lt;p&gt;That's all! If you found something interesting and you want to share it with newsletter members or you have an opinion on how to improve the newsletter don't be shy to email me. Since it's just the first edition of newsletter I'm experimenting with content and format. &lt;/p&gt;

&lt;p&gt;It would be if you invite your friends or colleagues to join the newsletter.&lt;/p&gt;

&lt;p&gt;I'll see you next week!&lt;/p&gt;

&lt;p&gt;Byteski&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>node</category>
      <category>typescript</category>
    </item>
    <item>
      <title>How To Configure tsconfig.json: TypeScript Strict options</title>
      <dc:creator>Max Kovalevsky</dc:creator>
      <pubDate>Thu, 29 Jul 2021 14:47:49 +0000</pubDate>
      <link>https://dev.to/kovalevsky/how-to-configure-tsconfig-json-typescript-strict-options-4c1c</link>
      <guid>https://dev.to/kovalevsky/how-to-configure-tsconfig-json-typescript-strict-options-4c1c</guid>
      <description>&lt;p&gt;This post is part of series of posts about TypeScript called &lt;strong&gt;&lt;em&gt;Grokking TypeScript&lt;/em&gt;&lt;/strong&gt;. It will guide you from scratch to writing full TypeScript applications on Back End and Front End. The series is available as &lt;strong&gt;PDF eBook&lt;/strong&gt; for &lt;strong&gt;free&lt;/strong&gt; to &lt;strong&gt;everyone&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://byte.ski/typescript-book" rel="noopener noreferrer"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F7iywoyv29h0zsxfculms.png" alt="Grokking TypeScript eBook (pdf)" width="409" height="117"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;TypeScript is not just a superset of JavaScript with static types. It is also a quite configurable tool that can be used for different types of projects. One parameter or group of parameters that can be configured is &lt;strong&gt;strict&lt;/strong&gt;. If you are not familiar with strict mode and why you should use it for a new project then check out the post  &lt;a href="https://byte.ski/blog/article/what-is-strict-mode-in-typescript-and-why-and-when-you-should-use-it" rel="noopener noreferrer"&gt;What Is Strict Mode In TypeScript, Why And When You Should Use It?&lt;/a&gt;. In this post I focus more on a practical side of this topic. &lt;/p&gt;

&lt;p&gt;TypeScript's strict mode parameter can be configurated as several individual parameters for each specific case of type checking. So, basically, if you set the parameter &lt;strong&gt;strict&lt;/strong&gt; to &lt;em&gt;true&lt;/em&gt; in &lt;strong&gt;tsconfig.json&lt;/strong&gt; it means that all these strict options are set to &lt;em&gt;true&lt;/em&gt;. &lt;/p&gt;

&lt;p&gt;List of strict options:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;useUnknownInCatchVariables (new)&lt;/li&gt;
&lt;li&gt;noImplicitAny&lt;/li&gt;
&lt;li&gt;strictNullChecks&lt;/li&gt;
&lt;li&gt;strictFunctionTypes&lt;/li&gt;
&lt;li&gt;strictBindCallApply&lt;/li&gt;
&lt;li&gt;strictPropertyInitialization&lt;/li&gt;
&lt;li&gt;noImplicitThis&lt;/li&gt;
&lt;li&gt;alwaysStrict&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Let's explore each strict option in practice.&lt;/p&gt;

&lt;h2&gt;
  
  
  TypeScript Strict options in tsconfig.json: useUnknownInCatchVariables
&lt;/h2&gt;

&lt;p&gt;This option was introduced in &lt;a href="https://devblogs.microsoft.com/typescript/announcing-typescript-4-4-beta/#use-unknown-catch-variables" rel="noopener noreferrer"&gt;TypeScript 4.4&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;The problem is that when we use construction &lt;strong&gt;try catch&lt;/strong&gt; the type of variable &lt;strong&gt;error&lt;/strong&gt; in &lt;em&gt;catch&lt;/em&gt; is &lt;strong&gt;any&lt;/strong&gt;:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fsyop03gxs0dkf76m6fa3.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fsyop03gxs0dkf76m6fa3.png" alt="Screenshot of an example in VSCode 1" width="639" height="423"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;It increases the potential risk of errors and application malfunction. The option &lt;strong&gt;useUnknownInCatchVariables&lt;/strong&gt; solves this problem.&lt;/p&gt;

&lt;p&gt;If you set option &lt;strong&gt;useUnknownInCatchVariables&lt;/strong&gt; to &lt;code&gt;true&lt;/code&gt; then variable &lt;strong&gt;error&lt;/strong&gt; in every &lt;strong&gt;try catch&lt;/strong&gt; in your code base will have type &lt;code&gt;unknown&lt;/code&gt;:&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;"compilerOptions"&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="err"&gt;//&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="err"&gt;...&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="nl"&gt;"useUnknownInCatchVariables"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="kc"&gt;true&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;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fr3ji0oli4oeq3a3q6i0h.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fr3ji0oli4oeq3a3q6i0h.png" alt="Screenshot of an example in VSCode 1" width="629" height="417"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;You can also use type &lt;strong&gt;Error&lt;/strong&gt; for error variable:&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;try&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="c1"&gt;// some code&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="k"&gt;catch &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;e&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;if &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;e&lt;/span&gt; &lt;span class="k"&gt;instanceof&lt;/span&gt; &lt;span class="nb"&gt;Error&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;error&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;e&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;message&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;h2&gt;
  
  
  TypeScript Strict options in tsconfig.json: noImplicitAny
&lt;/h2&gt;

&lt;p&gt;Let's start with option &lt;strong&gt;noImplicitAny&lt;/strong&gt;. &lt;/p&gt;

&lt;p&gt;In the &lt;strong&gt;main.ts&lt;/strong&gt; file (or whatever file you want) let's create a simple function:&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="nf"&gt;printData&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;data&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;data&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;If you run &lt;code&gt;tsc&lt;/code&gt; command you will see that TypeScript successfully compiles the code because there is no error.&lt;/p&gt;

&lt;p&gt;Now, set the options in configuration file &lt;strong&gt;tsconfig.json&lt;/strong&gt; in your project:&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;"compilerOptions"&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;"noImplicitAny"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="kc"&gt;true&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;If you're writing your code in an editor like &lt;a href="https://byte.ski/notes/Visual-Studio-Code" rel="noopener noreferrer"&gt;Visual Studio Code&lt;/a&gt; or some IDE you probably already see that something is wrong with parameter &lt;strong&gt;data&lt;/strong&gt; in the function. Let's run TypeScript compiler &lt;code&gt;tsc&lt;/code&gt; and see what it will tell us.&lt;/p&gt;

&lt;p&gt;TypeScript compiler will print something like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;error TS7006: Parameter 'data' implicitly has an 'any' type.

4 function printData(data) {
                     ~~~~
Found 1 error.
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;So, if you set the option &lt;strong&gt;noImplicitAny&lt;/strong&gt; to &lt;code&gt;true&lt;/code&gt;, TypeScript won't allow us to write functions with parameters without types of parameters. The thing is that TypeScript doesn't know what type of the parameter &lt;strong&gt;data&lt;/strong&gt; is and it doesn't &lt;em&gt;infer&lt;/em&gt; because there is no information in the code about that value should be there. &lt;/p&gt;

&lt;p&gt;You need to set some type to avoid this TypeScript error. For example, I'll specify type &lt;strong&gt;string&lt;/strong&gt; for the data:&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="nf"&gt;printData&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;data&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="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;data&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;Also, if your parameter is not required, you can specify the default value of the parameter. And there is the thing: if you set the default value of the parameter then you won't need to specify the type. In that case, TypeScript will understand what type of the parameter is by &lt;em&gt;Type inference&lt;/em&gt;.&lt;/p&gt;

&lt;p&gt;An example. The default value of the parameter is empty &lt;strong&gt;string&lt;/strong&gt; so type of the parameter is &lt;strong&gt;string&lt;/strong&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="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;printData&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;data&lt;/span&gt; &lt;span class="o"&gt;=&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="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;data&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;
  
  
  TypeScript Strict options in tsconfig.json: Why Should noImplicitAny Be Enabled?
&lt;/h3&gt;

&lt;p&gt;By setting the option &lt;strong&gt;noImplicitAny&lt;/strong&gt; to &lt;code&gt;true&lt;/code&gt;, TypeScript forces you to write safer code. How? The problem with ignorance of the type of the parameter is that you can manipulate the value in the code by methods that can't work with this value. For example, inside the function &lt;strong&gt;printData&lt;/strong&gt; you can use method &lt;strong&gt;.toLowerCase&lt;/strong&gt; that works with type &lt;strong&gt;string&lt;/strong&gt;. Your colleague (or even you!) can use the function &lt;strong&gt;printData&lt;/strong&gt; somewhere in the future. Because you don't know what the type of the parameter &lt;strong&gt;data&lt;/strong&gt; is, you probably can put the number value to this parameter.&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="nf"&gt;printData&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;data&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;data&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;toLowerCase&lt;/span&gt;&lt;span class="p"&gt;());&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="k"&gt;async&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;main&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nf"&gt;printData&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;10&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="nf"&gt;main&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The code above will successfully be compiled by &lt;code&gt;tsc&lt;/code&gt; because there are no errors from the TypeScript perspective. But when you will run the program in the &lt;a href="https://byte.ski/notes/Web-browser" rel="noopener noreferrer"&gt;Web browser&lt;/a&gt; or by &lt;a href="https://byte.ski/notes/Node" rel="noopener noreferrer"&gt;Node&lt;/a&gt; as in our case, you will see that program falls:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;node dist/main.js
/ts-node-sample/dist/main.js:13
    console.log(data.toLowerCase());
                     ^
TypeError: data.toLowerCase is not a function
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You can avoid this error before executing the code by specifying the type of the parameter. The TypeScript's option &lt;strong&gt;noImplicitAny&lt;/strong&gt; won't allow you to escape from specifying the type in the new code.&lt;/p&gt;

&lt;h2&gt;
  
  
  TypeScript Strict options in tsconfig.json: strictNullChecks
&lt;/h2&gt;

&lt;blockquote&gt;
&lt;p&gt;Source code of this example is available on  &lt;a href="https://github.com/kowalevski/ts-node-sample/tree/strict-options-strict-null-checks" rel="noopener noreferrer"&gt;GitHub&lt;/a&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;This parameter obligates us to make a check of the variable existing. For example, let's say we have an array of some object. This data is available in a code of app from JSON file:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;src/inventory.json&lt;/strong&gt;&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="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
        &lt;/span&gt;&lt;span class="nl"&gt;"id"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"1"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
        &lt;/span&gt;&lt;span class="nl"&gt;"name"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"sword"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
        &lt;/span&gt;&lt;span class="nl"&gt;"level"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"10"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
        &lt;/span&gt;&lt;span class="nl"&gt;"icon"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&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;span class="nl"&gt;"id"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"2"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
        &lt;/span&gt;&lt;span class="nl"&gt;"name"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"bow"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
        &lt;/span&gt;&lt;span class="nl"&gt;"level"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"7"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
        &lt;/span&gt;&lt;span class="nl"&gt;"icon"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&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;span class="nl"&gt;"id"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"3"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
        &lt;/span&gt;&lt;span class="nl"&gt;"name"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"shield"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
        &lt;/span&gt;&lt;span class="nl"&gt;"level"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"5"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
        &lt;/span&gt;&lt;span class="nl"&gt;"icon"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&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;In some modules, we have a code where this JSON file is imported and used as a database. The app is simple: it asks the user to type the name of the item from inventory and then if this item exists the program will print information about it.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;src/main.ts&lt;/strong&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;createQuestioner&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="s2"&gt;./createQuestioner&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;greeting&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="s2"&gt;./greeting&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nx"&gt;inventory&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;./inventory.json&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="k"&gt;async&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;main&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;try&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;questioner&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;createQuestioner&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;username&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nx"&gt;questioner&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;ask&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Type your username: &lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

    &lt;span class="nf"&gt;greeting&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;username&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;itemName&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nx"&gt;questioner&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;ask&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
      &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Type the name of the inventory item: &lt;/span&gt;&lt;span class="dl"&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;foundItem&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;inventory&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;find&lt;/span&gt;&lt;span class="p"&gt;((&lt;/span&gt;&lt;span class="nx"&gt;item&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;item&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;name&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="nx"&gt;itemName&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

    &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
      &lt;span class="s2"&gt;`You've chosen an item: &lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;foundItem&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;icon&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt; &lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;foundItem&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;name&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt; (lvl &lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;foundItem&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;level&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;)`&lt;/span&gt;
    &lt;span class="p"&gt;);&lt;/span&gt;

    &lt;span class="nx"&gt;questioner&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;finishUp&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;catch &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;e&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;error&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;e&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="nf"&gt;main&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If you run this program by &lt;code&gt;npm run dev&lt;/code&gt;, type any name and one of three item's names (sword, bow, shield) the program will run as it should. The problems begin when you type the name of the item that &lt;em&gt;does not exist&lt;/em&gt; in the inventory. If you try this, you'll see something like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;‚Äö√π√ò npm run dev

&amp;gt; tsc-intro@1.0.0 dev
&amp;gt; tsc &amp;amp;&amp;amp; node dist/main.js

Type your username: byte
Hello, @byte!
Type the name of the inventory item: spear
TypeError: Cannot read property 'icon' of undefine
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;All we need to do to fix this problem is to add the code that checks the variable existing before using it for printing the result. But the point is that &lt;a href="https://byte.ski/notes/TypeScript" rel="noopener noreferrer"&gt;TypeScript&lt;/a&gt; should highlight that we need to fix the potential problem. To do it just set option &lt;strong&gt;strictNullChecks&lt;/strong&gt; to &lt;em&gt;true&lt;/em&gt;:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;tsconfig.json&lt;/strong&gt;&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;"compilerOptions"&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="err"&gt;//&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="err"&gt;...&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="nl"&gt;"strictNullChecks"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="kc"&gt;true&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;Now, let's run &lt;code&gt;npm run dev&lt;/code&gt; and see that happens:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;src/main.ts:20:33 - error TS2532: Object is possibly &lt;span class="s1"&gt;'undefined'&lt;/span&gt;&lt;span class="nb"&gt;.&lt;/span&gt;

20       &lt;span class="sb"&gt;`&lt;/span&gt;You&lt;span class="s1"&gt;'ve chosen an item: ${foundItem.icon} ${foundItem.name} (lvl ${foundItem.level})`
                                   ~~~~~~~~~

src/main.ts:20:51 - error TS2532: Object is possibly '&lt;/span&gt;undefined&lt;span class="s1"&gt;'.

20       `You'&lt;/span&gt;ve chosen an item: &lt;span class="k"&gt;${&lt;/span&gt;&lt;span class="nv"&gt;foundItem&lt;/span&gt;&lt;span class="p"&gt;.icon&lt;/span&gt;&lt;span class="k"&gt;}&lt;/span&gt; &lt;span class="k"&gt;${&lt;/span&gt;&lt;span class="nv"&gt;foundItem&lt;/span&gt;&lt;span class="p"&gt;.name&lt;/span&gt;&lt;span class="k"&gt;}&lt;/span&gt; &lt;span class="o"&gt;(&lt;/span&gt;lvl &lt;span class="k"&gt;${&lt;/span&gt;&lt;span class="nv"&gt;foundItem&lt;/span&gt;&lt;span class="p"&gt;.level&lt;/span&gt;&lt;span class="k"&gt;}&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt;&lt;span class="sb"&gt;`&lt;/span&gt;
                                                     ~~~~~~~~~

src/main.ts:20:74 - error TS2532: Object is possibly &lt;span class="s1"&gt;'undefined'&lt;/span&gt;&lt;span class="nb"&gt;.&lt;/span&gt;

20       &lt;span class="sb"&gt;`&lt;/span&gt;You&lt;span class="s1"&gt;'ve chosen an item: ${foundItem.icon} ${foundItem.name} (lvl ${foundItem.level})`
                                                                            ~~~~~~~~~

Found 3 errors
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Great! Now we have information about where the problem is. Just add checking the variable &lt;strong&gt;foundItem&lt;/strong&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;async&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;main&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;try&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;questioner&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;createQuestioner&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;username&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nx"&gt;questioner&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;ask&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Type your username: &lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

    &lt;span class="nf"&gt;greeting&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;username&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;itemName&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nx"&gt;questioner&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;ask&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
      &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Type the name of the inventory item: &lt;/span&gt;&lt;span class="dl"&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;foundItem&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;inventory&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;find&lt;/span&gt;&lt;span class="p"&gt;((&lt;/span&gt;&lt;span class="nx"&gt;item&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;item&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;name&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="nx"&gt;itemName&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

    &lt;span class="k"&gt;if &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;!&lt;/span&gt;&lt;span class="nx"&gt;foundItem&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;`There is no item with name '&lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;itemName&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;' in the inventory.`&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
      &lt;span class="nx"&gt;questioner&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;finishUp&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;}&lt;/span&gt;

    &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
      &lt;span class="s2"&gt;`You've chosen an item: &lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;foundItem&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;icon&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt; &lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;foundItem&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;name&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt; (lvl &lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;foundItem&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;level&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;)`&lt;/span&gt;
    &lt;span class="p"&gt;);&lt;/span&gt;

    &lt;span class="nx"&gt;questioner&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;finishUp&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;catch &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;e&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;error&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;e&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;h3&gt;
  
  
  TypeScript Strict options in tsconfig.json: strictNullChecks and Exclamation mark
&lt;/h3&gt;

&lt;p&gt;You can also use "!" in such a case when &lt;strong&gt;you are sure&lt;/strong&gt; that found item or element exist. Let's see an example:&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;async&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;main&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;try&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;questioner&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;createQuestioner&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;username&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nx"&gt;questioner&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;ask&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Type your username: &lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

    &lt;span class="nf"&gt;greeting&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;username&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;listOfItems&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;inventory&lt;/span&gt;
      &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;map&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
        &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;item&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="s2"&gt;`&lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;item&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;id&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;) &lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;item&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;icon&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt; &lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;item&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;name&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt; (lvl &lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;item&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;level&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;)`&lt;/span&gt;
      &lt;span class="p"&gt;)&lt;/span&gt;
      &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;join&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="se"&gt;\n&lt;/span&gt;&lt;span class="dl"&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;option&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nx"&gt;questioner&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;ask&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
      &lt;span class="s2"&gt;`\n&lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;listOfItems&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;\n\nChoose the item (type the number): `&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;itemsIds&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;inventory&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;map&lt;/span&gt;&lt;span class="p"&gt;((&lt;/span&gt;&lt;span class="nx"&gt;item&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;item&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;id&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

    &lt;span class="k"&gt;if &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;!&lt;/span&gt;&lt;span class="nx"&gt;itemsIds&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;includes&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;option&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;`There is no item with option number &lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;option&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;.`&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
      &lt;span class="nx"&gt;questioner&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;finishUp&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;}&lt;/span&gt;

    &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;foundItem&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;inventory&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;find&lt;/span&gt;&lt;span class="p"&gt;((&lt;/span&gt;&lt;span class="nx"&gt;item&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;item&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;id&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="nx"&gt;option&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

    &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
      &lt;span class="s2"&gt;`You've chosen an item: &lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;foundItem&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;icon&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt; &lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;foundItem&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;name&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt; (lvl &lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;foundItem&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;level&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;)`&lt;/span&gt;
    &lt;span class="p"&gt;);&lt;/span&gt;

    &lt;span class="nx"&gt;questioner&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;finishUp&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;catch &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;e&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;error&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;e&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In this case, a user is not typing the name of the inventory item but type an option number offered by the app. Because the code checks that the user typed option number that surely exists (the line &lt;code&gt;if (!itemsIds.includes(option)) {&lt;/code&gt;) we don't need to manually check that variable &lt;strong&gt;foundItem&lt;/strong&gt; has data inside. But TypeScript will tell us that we need to check this variable because &lt;em&gt;Object is possibly 'undefined'&lt;/em&gt;. To avoid this highlight we can use &lt;strong&gt;exclamation mark&lt;/strong&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="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
  &lt;span class="s2"&gt;`You've chosen an item: &lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;foundItem&lt;/span&gt;&lt;span class="o"&gt;!&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;icon&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt; &lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;foundItem&lt;/span&gt;&lt;span class="o"&gt;!&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;name&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt; (lvl &lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;
    &lt;span class="nx"&gt;foundItem&lt;/span&gt;&lt;span class="o"&gt;!&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;level&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;)`&lt;/span&gt;
&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;It tells TypeScript that we are totally sure that &lt;strong&gt;foundItem&lt;/strong&gt; is not undefined or null. After that you can run the app it will work correctly.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;I recommend not use **exclamation mark&lt;/em&gt;* very often because it can expand the count of potential mistakes in the future. Use it only in case when &lt;strong&gt;you are totally sure&lt;/strong&gt; that some data exists.*&lt;/p&gt;

&lt;h2&gt;
  
  
  TypeScript Strict options in tsconfig.json: strictBindCallApply
&lt;/h2&gt;

&lt;blockquote&gt;
&lt;p&gt;Source code of this example is available on &lt;a href="https://github.com/kowalevski/ts-node-sample/tree/strict-options-strict-bind-call-apply" rel="noopener noreferrer"&gt;GitHub&lt;/a&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;The next option is not so useful nowadays since we don't need to use &lt;strong&gt;bind()&lt;/strong&gt; and related methods much often in modern JavaScript. But anyway, if you need to use bind(), call(), or apply() then this option might be useful for you.&lt;/p&gt;

&lt;p&gt;The example is unusual but you may come across this in existing projects with an old version of ECMAScript (where arrow functions are not available or their support is disabled for some reason). This function creates an object of a non-player character. You can start the dialog with this character (in our example it starts automatically after running the app) but the character is busy right now so it answers later (after 2 sec):&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;Questioner&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="s2"&gt;./createQuestioner&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;createMerchant&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;name&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="nx"&gt;questioner&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;Questioner&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;async&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;greeting&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;caller&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nl"&gt;name&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="nl"&gt;level&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;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="se"&gt;\n&lt;/span&gt;&lt;span class="s2"&gt;Did you complete the quest? &lt;/span&gt;&lt;span class="se"&gt;\n&lt;/span&gt;&lt;span class="s2"&gt; 1) yes &lt;/span&gt;&lt;span class="se"&gt;\n&lt;/span&gt;&lt;span class="s2"&gt; 2) no&lt;/span&gt;&lt;span class="dl"&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;answer&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nx"&gt;questioner&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;ask&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="se"&gt;\n&lt;/span&gt;&lt;span class="s2"&gt;Your answer: &lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

    &lt;span class="k"&gt;if &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;answer&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;1&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="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;`\nExcellent! Now your level is: &lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;caller&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;level&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;`&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;else&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="se"&gt;\n&lt;/span&gt;&lt;span class="s2"&gt;See ya later&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="nx"&gt;questioner&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;finishUp&lt;/span&gt;&lt;span class="p"&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;character&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;name&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="na"&gt;startDialog&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nf"&gt;function &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="na"&gt;caller&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="na"&gt;name&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="nl"&gt;level&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="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;[This character is busy now]&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
      &lt;span class="nf"&gt;setTimeout&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;greeting&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;bind&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;caller&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt; &lt;span class="mi"&gt;2000&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="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;character&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;Let's create a merchant in &lt;strong&gt;main&lt;/strong&gt; module:&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;createQuestioner&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="s2"&gt;./createQuestioner&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;greeting&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="s2"&gt;./greeting&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;createMerchant&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="s2"&gt;./merchant&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="k"&gt;async&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;main&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;try&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;questioner&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;createQuestioner&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;username&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nx"&gt;questioner&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;ask&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Type your username: &lt;/span&gt;&lt;span class="dl"&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;level&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nx"&gt;questioner&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;ask&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Type your level: &lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

    &lt;span class="nf"&gt;greeting&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;username&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;merchant&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;createMerchant&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Trader&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;questioner&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

    &lt;span class="nx"&gt;merchant&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;startDialog&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt; &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;username&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;level&lt;/span&gt; &lt;span class="p"&gt;});&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;catch &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;e&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;error&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;e&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="nf"&gt;main&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now, if you run the program and type your name and level (for example, 10) and then answer "yes" in dialog (type "1") when you see something goes wrong with your level:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;Excellent! Now your level is: 10
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Typical problem with &lt;code&gt;string&lt;/code&gt; and &lt;code&gt;number&lt;/code&gt; values in &lt;a href="https://byte.ski/notes/JavaScript" rel="noopener noreferrer"&gt;JavaScript&lt;/a&gt;. Notice that in &lt;strong&gt;createMerchant&lt;/strong&gt; in method &lt;strong&gt;startDialog&lt;/strong&gt; a parameter &lt;em&gt;level&lt;/em&gt; has type &lt;code&gt;string&lt;/code&gt; but in function &lt;strong&gt;greeting&lt;/strong&gt; the parameter &lt;em&gt;caller&lt;/em&gt; has field &lt;em&gt;level&lt;/em&gt; with type &lt;code&gt;number&lt;/code&gt;. But we don't have any type checking errors after running &lt;strong&gt;tsc&lt;/strong&gt;. We should tell TypeScript to check parameters of function that called by &lt;strong&gt;bind()&lt;/strong&gt; (call(), apply()). This is what option &lt;strong&gt;strictBindCallApply&lt;/strong&gt; is for.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;tsconfig.json&lt;/strong&gt;&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;"compilerOptions"&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="err"&gt;//&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="err"&gt;...&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="nl"&gt;"strictBindCallApply"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="kc"&gt;true&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;Now, if you run the program you will see that TypeScript highlights the problem with different types of field &lt;em&gt;level&lt;/em&gt; in function &lt;strong&gt;createMerchant&lt;/strong&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;src/merchant.ts:21:38 - error TS2769: No overload matches this call.
...
21       setTimeout&lt;span class="o"&gt;(&lt;/span&gt;greeting.bind&lt;span class="o"&gt;(&lt;/span&gt;this, &lt;span class="nb"&gt;caller&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt;, 2000&lt;span class="o"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
                                        ~~~~~~
Found 1 error.
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  TypeScript Strict options in tsconfig.json: strictFunctionTypes
&lt;/h2&gt;

&lt;p&gt;This option is intended for quite specific cases. If this option was set to &lt;em&gt;true&lt;/em&gt; then TypeScript will not allow you to use a function in a case when types of parameters of this function are not the same as parameter's types in specified &lt;em&gt;type&lt;/em&gt;.&lt;/p&gt;

&lt;p&gt;An example:&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;type&lt;/span&gt; &lt;span class="nx"&gt;loggerFn&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;id&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kr"&gt;number&lt;/span&gt; &lt;span class="o"&gt;|&lt;/span&gt; &lt;span class="kr"&gt;string&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="k"&gt;void&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;logTransaction&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;loggerFn&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;id&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="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;`[&lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Date&lt;/span&gt;&lt;span class="p"&gt;().&lt;/span&gt;&lt;span class="nf"&gt;toDateString&lt;/span&gt;&lt;span class="p"&gt;()}&lt;/span&gt;&lt;span class="s2"&gt;] &lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;id&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;trim&lt;/span&gt;&lt;span class="p"&gt;()}&lt;/span&gt;&lt;span class="s2"&gt;`&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;};&lt;/span&gt;

&lt;span class="nf"&gt;logTransaction&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;transactionId&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In this case, if options are enabled, &lt;strong&gt;tsc&lt;/strong&gt; will return an error message after running:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;src/main.ts:11:11 - error TS2322: Type &lt;span class="s1"&gt;'(id: string) =&amp;gt; void'&lt;/span&gt; is not assignable to &lt;span class="nb"&gt;type&lt;/span&gt; &lt;span class="s1"&gt;'loggerFn'&lt;/span&gt;&lt;span class="nb"&gt;.&lt;/span&gt;
  Types of parameters &lt;span class="s1"&gt;'id'&lt;/span&gt; and &lt;span class="s1"&gt;'id'&lt;/span&gt; are incompatible.
    Type &lt;span class="s1"&gt;'string | number'&lt;/span&gt; is not assignable to &lt;span class="nb"&gt;type&lt;/span&gt; &lt;span class="s1"&gt;'string'&lt;/span&gt;&lt;span class="nb"&gt;.&lt;/span&gt;
      Type &lt;span class="s1"&gt;'number'&lt;/span&gt; is not assignable to &lt;span class="nb"&gt;type&lt;/span&gt; &lt;span class="s1"&gt;'string'&lt;/span&gt;&lt;span class="nb"&gt;.&lt;/span&gt;

11     const logTransaction: loggerFn &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;id&lt;/span&gt;: string&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
             ~~~~~~~~~~~~~~~
Found 1 error
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Theoretically, in this case you could specify the parameter &lt;strong&gt;id&lt;/strong&gt; as a number and call function &lt;strong&gt;logTransaction&lt;/strong&gt; like that: &lt;code&gt;logTransaction(parseInt(transactionId))&lt;/code&gt;. But still, you will have a type-checking error because you cannot use method &lt;strong&gt;trim()&lt;/strong&gt; for a number value. &lt;/p&gt;

&lt;p&gt;Anyway, is good to know what specific options are needed if you enabled &lt;strong&gt;strict mode&lt;/strong&gt; in your project.&lt;/p&gt;

&lt;h2&gt;
  
  
  TypeScript Strict options in tsconfig.json: noImplicitThis
&lt;/h2&gt;

&lt;p&gt;You might know that &lt;a href="https://byte.ski/notes/JavaScript" rel="noopener noreferrer"&gt;JavaScript&lt;/a&gt; has a quite important nuance with the variable "this". Let's say, you have a method that prints a value of an object's field. If you wrote this method as &lt;em&gt;function declaration&lt;/em&gt; then will lose "this" of an object where the method is specified. I would say that it's one of the famous "features" of &lt;a href="https://byte.ski/notes/JavaScript" rel="noopener noreferrer"&gt;JavaScript&lt;/a&gt; and Internet has tons of materials about this.&lt;/p&gt;

&lt;p&gt;Here is an example:&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;createCharacter&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;name&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="nx"&gt;level&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;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="na"&gt;label&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;`[&lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;level&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt; lvl] &lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;name&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;`&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="nf"&gt;info&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="na"&gt;prefix&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="k"&gt;return&lt;/span&gt; &lt;span class="nf"&gt;function &lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;`&lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;prefix&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;: &lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;label&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;`&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
      &lt;span class="p"&gt;};&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
  &lt;span class="p"&gt;};&lt;/span&gt;
&lt;span class="p"&gt;};&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;ranger&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;createCharacter&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Ranger&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;77&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;printRangerInfo&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;ranger&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;info&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Neutral&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="nf"&gt;printRangerInfo&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;After running &lt;code&gt;npm run dev&lt;/code&gt; you will see that it throws an error:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;TypeError: Cannot &lt;span class="nb"&gt;read &lt;/span&gt;property &lt;span class="s1"&gt;'label'&lt;/span&gt; of undefined
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now, let's set option &lt;strong&gt;noImplicitThis&lt;/strong&gt; in configuration file:&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;"compilerOptions"&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="err"&gt;//&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="err"&gt;...&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="nl"&gt;"noImplicitThis"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="kc"&gt;true&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;After that &lt;a href="https://byte.ski/notes/TypeScript" rel="noopener noreferrer"&gt;TypeScript&lt;/a&gt; will highlight an error in the code:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;error TS2683: &lt;span class="s1"&gt;'this'&lt;/span&gt; implicitly has &lt;span class="nb"&gt;type&lt;/span&gt; &lt;span class="s1"&gt;'any'&lt;/span&gt; because it does not have a &lt;span class="nb"&gt;type &lt;/span&gt;annotation.
14             console.log&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="sb"&gt;`&lt;/span&gt;&lt;span class="k"&gt;${&lt;/span&gt;&lt;span class="nv"&gt;prefix&lt;/span&gt;&lt;span class="k"&gt;}&lt;/span&gt;: &lt;span class="k"&gt;${&lt;/span&gt;&lt;span class="nv"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.label&lt;/span&gt;&lt;span class="k"&gt;}&lt;/span&gt;&lt;span class="sb"&gt;`&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
                                         ~~~~
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;13           &lt;span class="k"&gt;return function&lt;/span&gt; &lt;span class="o"&gt;()&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
                    ~~~~~~~~
An outer value of &lt;span class="s1"&gt;'this'&lt;/span&gt; is shadowed by this container.
Found 1 error
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;By doing so we can fix the problem before running an application. One of a solution, in this case, is using an arrow function:&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;createCharacter&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;name&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="nx"&gt;level&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;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="na"&gt;label&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;`[&lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;level&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt; lvl] &lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;name&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;`&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="nf"&gt;info&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="na"&gt;prefix&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="k"&gt;return &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="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;`&lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;prefix&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;: &lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;label&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;`&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
      &lt;span class="p"&gt;};&lt;/span&gt;
    &lt;span class="p"&gt;},&lt;/span&gt;
  &lt;span class="p"&gt;};&lt;/span&gt;
&lt;span class="p"&gt;};&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;When you change the nested function to arrow one &lt;a href="https://byte.ski/notes/TypeScript" rel="noopener noreferrer"&gt;TypeScript&lt;/a&gt; will stop highlight this line as an error. After running &lt;code&gt;npm run dev&lt;/code&gt; you will see that the program works correctly.&lt;/p&gt;

&lt;h2&gt;
  
  
  TypeScript Strict options in tsconfig.json: strictPropertyInitialization
&lt;/h2&gt;

&lt;p&gt;The next option is directly related to classes in &lt;a href="https://byte.ski/notes/JavaScript" rel="noopener noreferrer"&gt;JavaScript&lt;/a&gt; and &lt;a href="https://byte.ski/notes/TypeScript" rel="noopener noreferrer"&gt;TypeScript&lt;/a&gt;. In TypeScript, you can specify the properties of the class and also their types. Here is an example.&lt;/p&gt;

&lt;p&gt;Let's say we have a special class for game characters:&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;export&lt;/span&gt; &lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;Character&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;name&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="nl"&gt;level&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="nf"&gt;constructor&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{}&lt;/span&gt;

  &lt;span class="nf"&gt;greeting&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;callerName&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="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;`[&lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;level&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;] &lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;name&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;: Hello, &lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;callerName&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;!`&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now, in the &lt;strong&gt;main&lt;/strong&gt; module we create a character's object. The character should greetings the player:&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;async&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;main&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;try&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;questioner&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;createQuestioner&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;name&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nx"&gt;questioner&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;ask&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Type your first name: &lt;/span&gt;&lt;span class="dl"&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;traveler&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Character&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;

    &lt;span class="nx"&gt;traveler&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;greeting&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;name&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

    &lt;span class="nx"&gt;questioner&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;finishUp&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;catch &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;e&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;error&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;e&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If you run this small example, you will see:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;Type your first name: Byte 
&lt;span class="o"&gt;[&lt;/span&gt;undefined] undefined: Hello, Byte!
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;I guess we didn't give a name to the traveler! Okay, we made a mistake in the code. It's not a big deal. The real problem is that &lt;a href="https://byte.ski/notes/TypeScript" rel="noopener noreferrer"&gt;TypeScript&lt;/a&gt; didn't say anything about it! Notice that &lt;code&gt;constructor&lt;/code&gt; of class &lt;strong&gt;Character&lt;/strong&gt; is empty. But also there is no highlighted error or warning. We don't have a specific syntax like &lt;code&gt;required name: string&lt;/code&gt; in TypeScript to declare that properties &lt;em&gt;name&lt;/em&gt; and &lt;em&gt;level&lt;/em&gt; are required for initialization in the class &lt;strong&gt;Character&lt;/strong&gt;. However, we can enable option &lt;strong&gt;strictPropertyInitialization&lt;/strong&gt; and after that &lt;a href="https://byte.ski/notes/TypeScript" rel="noopener noreferrer"&gt;TypeScript&lt;/a&gt; compiler will tell us that we didn't initialize properties name and level in the constructor method of class Character.&lt;/p&gt;

&lt;p&gt;An option &lt;strong&gt;strictPropertyInitialization&lt;/strong&gt; can be enabled only if option &lt;strong&gt;strictNullChecks&lt;/strong&gt; is enabled too.&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="c1"&gt;// ...&lt;/span&gt;
    &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;strictNullChecks&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="p"&gt;,&lt;/span&gt;
    &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;strictPropertyInitialization&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="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;And after that we run &lt;code&gt;tsc&lt;/code&gt; and see:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;error TS2564: Property &lt;span class="s1"&gt;'name'&lt;/span&gt; has no initializer and is not definitely assigned &lt;span class="k"&gt;in &lt;/span&gt;the constructor.

2   name: string&lt;span class="p"&gt;;&lt;/span&gt;
    ~~~~
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;src/Character.ts:3:3 - error TS2564: Property &lt;span class="s1"&gt;'level'&lt;/span&gt; has no initializer and is not definitely assigned &lt;span class="k"&gt;in &lt;/span&gt;the constructor.

3   level: string&lt;span class="p"&gt;;&lt;/span&gt;
    ~~~~~

Found 2 errors.
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This is exactly what we need. Now, let's fix the problem:&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;export&lt;/span&gt; &lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;Character&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="c1"&gt;// Class Property Inference from Constructors&lt;/span&gt;
  &lt;span class="c1"&gt;// since version 4.0 TypeScript can ‚Äö√Ñ√∫take" types of properties from a constructor&lt;/span&gt;
  &lt;span class="c1"&gt;// so we don't need to specify types of properties 'name' and 'level' here&lt;/span&gt;
  &lt;span class="nx"&gt;name&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nx"&gt;level&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

  &lt;span class="nf"&gt;constructor&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;name&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="nx"&gt;level&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;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;name&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;name&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;level&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;level&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;

  &lt;span class="nf"&gt;greeting&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;callerName&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="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;`[&lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;level&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;] &lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;name&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;: Hello, &lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;callerName&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;!`&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;And don't forget to give a name for the traveler in &lt;strong&gt;main&lt;/strong&gt; module!&lt;/p&gt;

&lt;h2&gt;
  
  
  TypeScript Strict options in tsconfig.json: alwaysStrict
&lt;/h2&gt;

&lt;p&gt;If you set the option &lt;strong&gt;alwaysStrict&lt;/strong&gt; to &lt;code&gt;true&lt;/code&gt; then &lt;a href="https://byte.ski/notes/TypeScript" rel="noopener noreferrer"&gt;TypeScript&lt;/a&gt; will parse your code in &lt;a href="https://byte.ski/notes/ECMAScript" rel="noopener noreferrer"&gt;ECMAScript&lt;/a&gt; Strict mode and put "use strict" in each source file. If you are not familiar with &lt;a href="https://byte.ski/notes/ECMAScript" rel="noopener noreferrer"&gt;ECMAScript&lt;/a&gt; Strict mode then check out &lt;a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Strict_mode" rel="noopener noreferrer"&gt;article on MDN&lt;/a&gt; about it.&lt;/p&gt;

&lt;h2&gt;
  
  
  Conclusions
&lt;/h2&gt;

&lt;p&gt;When you have already learned what errors can be prevented by TypeScript's strict options you may exclaim "It can be fixed by a few lines of code. Just add a checking of variable's existing before print it. What's the big deal?" and you'll be right. But, it's just a synthetic example to demonstrate the problem that can be solved by strict options. In reality, it could be one small part of a huge project with hundreds of files and thousands of lines of code. You cannot keep track of everything and you shouldn't. You also can make a typo or forget about doing a check because you can't concentrate after last night's party. It can also happen to your new colleague who hasn't completely figured out the codebase yet.&lt;/p&gt;

&lt;p&gt;The point is to delegate solving errors that are related to types of variables to tools like &lt;a href="https://byte.ski/notes/TypeScript" rel="noopener noreferrer"&gt;TypeScript&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;Do you like the material? Please, &lt;a href="https://byte.ski/newsletter" rel="noopener noreferrer"&gt;subscribe to my email newsletter&lt;/a&gt; to stay up to date.&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://byte.ski/newsletter" rel="noopener noreferrer"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ffld1yqfgvgz2dgcpho0x.png" alt="subscribe" width="545" height="153"&gt;&lt;/a&gt;&lt;/p&gt;

</description>
      <category>typescript</category>
      <category>javascript</category>
      <category>beginners</category>
    </item>
    <item>
      <title>What Is Strict Mode In TypeScript, Why And When You Should Use It?</title>
      <dc:creator>Max Kovalevsky</dc:creator>
      <pubDate>Fri, 16 Jul 2021 02:14:43 +0000</pubDate>
      <link>https://dev.to/kovalevsky/what-is-strict-mode-in-typescript-and-why-and-when-you-should-use-it-10p5</link>
      <guid>https://dev.to/kovalevsky/what-is-strict-mode-in-typescript-and-why-and-when-you-should-use-it-10p5</guid>
      <description>&lt;p&gt;This post is part of series and &lt;a href="https://byte.ski/typescript-book" rel="noopener noreferrer"&gt;book about TypeScript&lt;/a&gt;. It will guide you from scratch to writing full TypeScript applications on Back End and Front End. The series is available as &lt;strong&gt;PDF eBook&lt;/strong&gt; for &lt;strong&gt;free&lt;/strong&gt; to &lt;strong&gt;everyone&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://byte.ski/typescript-book" rel="noopener noreferrer"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fidg3cmsrhuu0jqx5bulp.png" alt="TypeScript Book (PDF)" width="409" height="117"&gt;&lt;/a&gt;  &lt;/p&gt;

&lt;p&gt;There are many options and parameters that can be used in the TypeScript configuration. One of the important "groups" of options is strict options. These options provide us the ability to write the safest code. How? Because TypeScript was developed primarily as &lt;strong&gt;superset of JavaScript&lt;/strong&gt;, by default it allows us to write code that is not super strict in types and other aspects. It was made like this because TypeScript should be easily used by JavaScript developers. JavaScript doesn't have static types and is more flexible in some aspects of programming. It has many features to write code &lt;em&gt;faster&lt;/em&gt; and &lt;em&gt;easier&lt;/em&gt; (at first). However, the other side of this is that you probably will have more places where your code is unsafe. It means that the count of cases where your program will fall is big. TypeScript partially solves this problem. &lt;/p&gt;

&lt;h2&gt;
  
  
  What Is Strict Mode?
&lt;/h2&gt;

&lt;p&gt;You may probably have heard about &lt;a href="https://byte.ski/notes/JavaScript" rel="noopener noreferrer"&gt;JavaScript&lt;/a&gt; strict mode and &lt;a href="https://byte.ski/notes/TypeScript" rel="noopener noreferrer"&gt;TypeScript&lt;/a&gt; strict mode. The point is that they are different kinds of things. &lt;/p&gt;

&lt;p&gt;TypeScript strict mode is a bunch of TypeScript compiler parameters (that can be also be represented by one "main" parameter) that make TypeScript compiler &lt;strong&gt;tsc&lt;/strong&gt; force you to follow specific rules of writing code in TypeScript. All these rules are directly related to &lt;strong&gt;types&lt;/strong&gt; and &lt;strong&gt;managing types&lt;/strong&gt; in the TypeScript code. For example, one of the rules forces you to always write a type of parameter in every function.&lt;/p&gt;

&lt;p&gt;TypeScript "strict mode" could be enabled in the TypeScript configuration file by one OR a few parameters. It's a group of parameters that can be enabled individually or can be enabled all at once by one parameter.&lt;/p&gt;

&lt;p&gt;The "main strict mode" parameter is called &lt;strong&gt;strict&lt;/strong&gt;. It is a part of &lt;strong&gt;compilerOptions&lt;/strong&gt; in &lt;strong&gt;tsconfig.json&lt;/strong&gt;. If you set this parameter to &lt;strong&gt;true&lt;/strong&gt; it will automatically set specific several parameters of configuration to &lt;strong&gt;true&lt;/strong&gt;. Another important nuance is that if you enable &lt;strong&gt;strict&lt;/strong&gt; parameter instead of individual strict checks parameters, the TypeScript compiler will &lt;em&gt;automatically&lt;/em&gt; check your code with all new strict checks parameters that TypeScript may have in the next versions. &lt;/p&gt;

&lt;p&gt;Strict checks parameters are:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;noImplicitAny&lt;/li&gt;
&lt;li&gt;strictNullChecks&lt;/li&gt;
&lt;li&gt;strictFunctionTypes&lt;/li&gt;
&lt;li&gt;strictBindCallApply&lt;/li&gt;
&lt;li&gt;strictPropertyInitialization&lt;/li&gt;
&lt;li&gt;noImplicitThis&lt;/li&gt;
&lt;li&gt;alwaysStrict&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;I will introduce you to each of these parameters in next posts of the series. Let's focus on &lt;strong&gt;strict mode&lt;/strong&gt; itself.&lt;/p&gt;

&lt;h2&gt;
  
  
  Should I Use Strict Mode?
&lt;/h2&gt;

&lt;p&gt;What happens when you set this parameter to &lt;strong&gt;true&lt;/strong&gt;? Well, it depends on is your project new (just created) or not. If you don't have any code in your project except configuration files or files with boilerplate code that was generated by tools like &lt;a href="https://byte.ski/notes/create-react-app" rel="noopener noreferrer"&gt;create-react-app&lt;/a&gt; then &lt;strong&gt;tsc&lt;/strong&gt; should compile the project without errors. But if your project is not new, have a huge amount of files and code and you didn't follow specific rules of strict mode then you probably will get a list of errors provided by &lt;strong&gt;tsc&lt;/strong&gt; after you attempted to compile the project.&lt;/p&gt;

&lt;p&gt;And this is an answer to the question "Should I use strict mode in TypeScript or not?". If you just start a new project &lt;strong&gt;I highly recommend using strict mode in TypeScript&lt;/strong&gt;. It will help you to avoid errors, typos, and mistakes in your code in the future. Strict mode constricts you in ways of writing your code. On other hand, you won't choose the way that will bring you to make a mistake. Sometimes a simple, verbose, and "boring" code is better than "cool" one-line code because it won't be failed. &lt;/p&gt;

&lt;p&gt;Why strict mode in TypeScript can be enabled by several parameters? These parameters can be used in an existing project. You probably won't be able to set parameter &lt;strong&gt;strict&lt;/strong&gt; to true in an existing project. But you can set some strict mode parameters to gradually rewrite your codebase following strict mode rules. For example, you can set the parameter &lt;strong&gt;noImplicitAny&lt;/strong&gt; to &lt;strong&gt;true&lt;/strong&gt; and rewrite your code to one that is following this rule (you should write a type of parameters in every function). You probably won't have time to rewrite all projects but you can improve specific parts of your code. Next time when you will have time to improve code quality you can set one more strict mode parameter (that suits your by time, number of changes in code, etc).&lt;/p&gt;

&lt;h2&gt;
  
  
  In Practice
&lt;/h2&gt;

&lt;p&gt;Let's look at the example. Here is the simple console app that asks a user to type its name and then if the user exists in a database (which is basically &lt;a href="https://byte.ski/notes/JSON" rel="noopener noreferrer"&gt;JSON&lt;/a&gt; file with an array of users) prints greetings in a terminal. The source of an example is available &lt;a href="https://github.com/kowalevski/ts-node-sample/tree/strict-mode-example" rel="noopener noreferrer"&gt;here&lt;/a&gt;. Just create a new TypeScript project and create a few files with the code presented below.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;git clone https://github.com/kowalevski/ts-node-sample/tree/strict-mode-example
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The app has three files or modules with functions. The entry point of the app is file &lt;strong&gt;src/main.ts&lt;/strong&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;createQuestioner&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="s2"&gt;./createQuestioner&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;greeting&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="s2"&gt;./greeting&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nx"&gt;usersDB&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;./users.json&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="k"&gt;async&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;main&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;try&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;questioner&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;createQuestioner&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;username&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nx"&gt;questioner&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;ask&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Type your name: &lt;/span&gt;&lt;span class="dl"&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;foundUser&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;usersDB&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;find&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="o"&gt;=&amp;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;username&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="nx"&gt;username&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

    &lt;span class="nf"&gt;greeting&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;foundUser&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;username&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

    &lt;span class="nx"&gt;questioner&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;finishUp&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;catch &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;e&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;error&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;e&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="nx"&gt;process&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;exit&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="nf"&gt;main&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;We are not interested in the module &lt;strong&gt;createQuestioner&lt;/strong&gt;. Let's perceive it as a third-party library with some API. What we really need to focus on is file &lt;strong&gt;src/greeting.ts&lt;/strong&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;export&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;greeting&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;names&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;`Hello, &lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;names&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;map&lt;/span&gt;&lt;span class="p"&gt;((&lt;/span&gt;&lt;span class="nx"&gt;name&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;name&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;toLowerCase&lt;/span&gt;&lt;span class="p"&gt;()).&lt;/span&gt;&lt;span class="nf"&gt;join&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;, &lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;)}&lt;/span&gt;&lt;span class="s2"&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;Pretty simple code, isn't it? We didn't specify the type of parameter names but we expect that there will be an array of strings. &lt;/p&gt;

&lt;p&gt;Okay, let's run our small application. Did you see any issues in the code? Because &lt;strong&gt;strict mode&lt;/strong&gt; is disabled in the TypeScript configuration of this app we shouldn't see any errors in the editor.&lt;/p&gt;

&lt;p&gt;Run the app by 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;tsc &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; node dist/main.js
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Or&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;npm run dev
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;After typing a name (it can be whatever name you want) you should see that there are errors in our code. But they were identified only after running &lt;strong&gt;Node&lt;/strong&gt;, i.e. in runtime. So, the TypeScript compiler didn't find any problems in the code. &lt;/p&gt;

&lt;p&gt;Now, let's enable &lt;strong&gt;strict mode&lt;/strong&gt; and see what happens. After enabling &lt;strong&gt;strict&lt;/strong&gt; parameter in &lt;strong&gt;tsconfig.json&lt;/strong&gt; you should see errors in your editor (if it supports TypeScript):&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fjxsb705df03jzelez2c5.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fjxsb705df03jzelez2c5.png" width="800" height="221"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;And if you run TypeScript compilation you will see that TypeScript highlight the error:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;src/greeting.ts:1:26 - error TS7006: Parameter 'names' implicitly has an 'any' type.

1 export function greeting(names) {
                           ~~~~~

src/greeting.ts:2:36 - error TS7006: Parameter 'name' implicitly has an 'any' type.

2   console.log(`Hello, ${names.map((name) =&amp;gt; name.toLowerCase()).join(', ')}!`);
                                     ~~~~
Found 2 errors
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Basically, the problem is that we didn't specify the type of parameter &lt;strong&gt;names&lt;/strong&gt; in a function &lt;strong&gt;greeting&lt;/strong&gt;. It means that the function can be called with wrong arguments in module &lt;strong&gt;main&lt;/strong&gt;. Specify the type in &lt;strong&gt;src/greeting.ts&lt;/strong&gt;. It should be an array of string values:&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;export&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;greeting&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;names&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="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;`Hello, &lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;names&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;map&lt;/span&gt;&lt;span class="p"&gt;((&lt;/span&gt;&lt;span class="nx"&gt;name&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;name&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;toLowerCase&lt;/span&gt;&lt;span class="p"&gt;()).&lt;/span&gt;&lt;span class="nf"&gt;join&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;, &lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;)}&lt;/span&gt;&lt;span class="s2"&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;Great! Let's see that we have in a file &lt;strong&gt;main.ts&lt;/strong&gt;. In an editor, you probably may see that there is an error. Let's run TypeScript and see what's wrong here.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;src/main.ts:12:14 - error TS2345: Argument of type '{ username: string; age: number; } | undefined' is not assignable to parameter of type 'string[]'.
  Type 'undefined' is not assignable to type 'string[]'.

12     greeting(foundUser.username);
                ~~~~~~~~~~~~~~~

Found 1 error
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Okay. So, the problem is that we put a value of variable &lt;strong&gt;foundUser&lt;/strong&gt; as itself (it is an object or undefined) but a function &lt;strong&gt;greeting&lt;/strong&gt; receives an array of string values. It seems like a small typo because all we need to do is write argument &lt;strong&gt;foundUser.username&lt;/strong&gt; as bracketed. Also, because variable &lt;strong&gt;foundUser&lt;/strong&gt; could be &lt;em&gt;undefined&lt;/em&gt; we need to check that is it false or not:&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;async&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;main&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;try&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;questioner&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;createQuestioner&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;username&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nx"&gt;questioner&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;ask&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Type your name: &lt;/span&gt;&lt;span class="dl"&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;foundUser&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;usersDB&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;find&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="o"&gt;=&amp;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;username&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="nx"&gt;username&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

    &lt;span class="k"&gt;if &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;!&lt;/span&gt;&lt;span class="nx"&gt;foundUser&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;User is not found&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
        &lt;span class="nx"&gt;questioner&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;finishUp&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;}&lt;/span&gt;

    &lt;span class="nf"&gt;greeting&lt;/span&gt;&lt;span class="p"&gt;([&lt;/span&gt;&lt;span class="nx"&gt;foundUser&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;username&lt;/span&gt;&lt;span class="p"&gt;]);&lt;/span&gt;

    &lt;span class="nx"&gt;questioner&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;finishUp&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;catch &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;e&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;error&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;e&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="nx"&gt;process&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;exit&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now, let's run the app again:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;npm run dev
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;It should work correctly.&lt;/p&gt;

&lt;h2&gt;
  
  
  Conclusions
&lt;/h2&gt;

&lt;p&gt;So now you know that even code that compiles by &lt;strong&gt;tsc&lt;/strong&gt; successfully can have issues and incorrect behavior when this code is running. The goal of TypeScript is to prevent times when the application works with errors or doesn't work at all &lt;strong&gt;&lt;em&gt;before&lt;/em&gt;&lt;/strong&gt; the code of the application executes. TypeScript analysis your code and based on types that were specified by you or by &lt;em&gt;type inference&lt;/em&gt; and highlight part of the code with potential risk. And the best way it works is in &lt;strong&gt;strict mode&lt;/strong&gt;. Using &lt;strong&gt;strict mode&lt;/strong&gt; you will catch more potential errors and typos in your codebase before running the program.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;Do you like the material? Please, &lt;a href="https://byte.ski/newsletter" rel="noopener noreferrer"&gt;subscribe to my email newsletter&lt;/a&gt; to stay up to date.&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://byte.ski/newsletter" rel="noopener noreferrer"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ffld1yqfgvgz2dgcpho0x.png" alt="subscribe" width="545" height="153"&gt;&lt;/a&gt;&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>typescript</category>
      <category>beginners</category>
    </item>
    <item>
      <title>Configuring TypeScript: options rootDir, outDir, module, target</title>
      <dc:creator>Max Kovalevsky</dc:creator>
      <pubDate>Tue, 18 May 2021 17:14:28 +0000</pubDate>
      <link>https://dev.to/kovalevsky/configuring-typescript-options-rootdir-outdir-module-target-1m38</link>
      <guid>https://dev.to/kovalevsky/configuring-typescript-options-rootdir-outdir-module-target-1m38</guid>
      <description>&lt;p&gt;This post is part of series and &lt;a href="https://byte.ski/typescript-book" rel="noopener noreferrer"&gt;book about TypeScript&lt;/a&gt;. It will guide you from scratch to writing full TypeScript applications on Back End and Front End. The series is available as &lt;strong&gt;PDF eBook&lt;/strong&gt; for &lt;strong&gt;free&lt;/strong&gt; to &lt;strong&gt;everyone&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://byte.ski/typescript-book" rel="noopener noreferrer"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fidg3cmsrhuu0jqx5bulp.png" alt="TypeScript Book (PDF)" width="409" height="117"&gt;&lt;/a&gt; &lt;/p&gt;

&lt;p&gt;In the post &lt;a href="https://byte.ski/blog/article/getting-started-using-and-configuring-typescript-compiler" rel="noopener noreferrer"&gt;Getting Started With TypeScript Compiler (tsc)&lt;/a&gt; we started to use TypeScript compiler with a few options in a simple Node project. We used &lt;strong&gt;tsc&lt;/strong&gt; command to compile our app with specific rules and in watch mode. It works but we can use much more options of TypeScript compiler. However, use it just like a command in the Terminal with a bunch of flags is not so comfortable. We can improve our workflow by using TypeScript configuration file - &lt;strong&gt;tsconfig.json&lt;/strong&gt;. In this post, we will learn how to create this file and configure it.&lt;/p&gt;

&lt;p&gt;The project example will be the same as in the post &lt;a href="https://byte.ski/blog/article/getting-started-using-and-configuring-typescript-compiler" rel="noopener noreferrer"&gt;Getting Started With TypeScript Compiler (tsc)&lt;/a&gt;. It is also available on GitHub as repository &lt;a href="https://github.com/mxkvl/ts-node-sample" rel="noopener noreferrer"&gt;mxkvl/ts-node-sample&lt;/a&gt;. If you didn't make the project from previous post from scratch - just download the repository from GitHub or clone the repository by this git command:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;git clone https://github.com/mxkvl/ts-node-sample.git
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Creating configuration file
&lt;/h2&gt;

&lt;p&gt;Alright, let's start with creating the TypeScript configuration file. In the root folder of the project just use &lt;strong&gt;tsc&lt;/strong&gt; with a special flag:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;tsc --init
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You will see the message from &lt;strong&gt;tsc&lt;/strong&gt; that the file was successfully created. Now we have a new file in the folder called &lt;strong&gt;tsconfig.json&lt;/strong&gt;. Let's look into this file. You will see a JSON with a bunch of different options. Most of them are commented but few options are already enabled by default. You can check out the whole commands with commentaries in &lt;strong&gt;tsconfig.json&lt;/strong&gt; or check out &lt;a href="https://aka.ms/tsconfig.json" rel="noopener noreferrer"&gt;documentation&lt;/a&gt; by yourself. In this guide, we will configure TypeScript for our small project from scratch so you need to delete all these options. Your &lt;strong&gt;tsconfig.json&lt;/strong&gt; should look like this:&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;"compilerOptions"&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;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;Okay. We already have the command from the previous post that compiles TypeScript with specific rules and in watch mode:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;tsc --module ESNext --outDir "./dist" --watch src/main.ts
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Just a reminder. It compiles file &lt;strong&gt;main.ts&lt;/strong&gt; that is in folder &lt;strong&gt;/src&lt;/strong&gt;. Compiled JavaScript files will be in the folder &lt;strong&gt;/dist&lt;/strong&gt;. The option &lt;strong&gt;--module ESNext&lt;/strong&gt; means that &lt;strong&gt;tsc&lt;/strong&gt; will compile files in JavaScript code with &lt;a href="https://byte.ski/notes/ES-Modules" rel="noopener noreferrer"&gt;ES Modules&lt;/a&gt;. &lt;/p&gt;

&lt;p&gt;Now, let's configure the TypeScript compiler in &lt;strong&gt;tsconfig.json&lt;/strong&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  rootDir and outDir
&lt;/h2&gt;

&lt;p&gt;First of all, we need to specify the folders for source code and output code. We already have folders &lt;strong&gt;/src&lt;/strong&gt; and &lt;strong&gt;/dist&lt;/strong&gt; for it. We just need to tell TypeScript to look at &lt;strong&gt;/src&lt;/strong&gt; as a folder that contains TypeScript files with source code and to compile all files into the folder &lt;strong&gt;/dist&lt;/strong&gt;. For this purpose we can use options &lt;strong&gt;rootDir&lt;/strong&gt; and &lt;strong&gt;outDir&lt;/strong&gt;.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;rootDir&lt;/strong&gt; is the path to the folder with the source code of the app (in our case it is &lt;strong&gt;/src&lt;/strong&gt;)&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;outDir&lt;/strong&gt; is the path to the folder with compiled JavaScript files that will be executed by Node or &lt;a href="https://byte.ski/notes/Web-browser" rel="noopener noreferrer"&gt;Web browser&lt;/a&gt; (in our case it is &lt;strong&gt;/dist&lt;/strong&gt;)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Change the &lt;strong&gt;tsconfig.json&lt;/strong&gt;:&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;"compilerOptions"&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;"rootDir"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"./src"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="nl"&gt;"outDir"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"./dist"&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;Delete the folder &lt;strong&gt;/dist&lt;/strong&gt; just to make sure that the TypeScript compiler will create it after compilation based on our configuration file:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;rm -r dist
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Because we use configuration file we don't need to use any options or specify file entry point (src/main.ts). Just use in the root folder of the project:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;tsc
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You will see that &lt;strong&gt;tsc&lt;/strong&gt; successfully created folder &lt;strong&gt;/dist&lt;/strong&gt; with compiled JavaScript code.&lt;/p&gt;

&lt;p&gt;Run the app just to make sure that everything works as before:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;node dist/main.js
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  module
&lt;/h2&gt;

&lt;p&gt;We already know from the post &lt;a href="https://byte.ski/blog/article/getting-started-using-and-configuring-typescript-compiler" rel="noopener noreferrer"&gt;Getting Started With TypeScript Compiler (tsc)&lt;/a&gt; that we can tell TypeScript to compile the code into JavaScript that uses &lt;a href="https://byte.ski/notes/ES-Modules" rel="noopener noreferrer"&gt;ES Modules&lt;/a&gt; instead of &lt;a href="https://byte.ski/notes/CommonJS-Modules" rel="noopener noreferrer"&gt;CommonJS Modules&lt;/a&gt;. For that purpose we used the special option of &lt;strong&gt;tsc&lt;/strong&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;tsc --module ESNext src/main.ts
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now we can specify it in &lt;strong&gt;tsconfig.json&lt;/strong&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;{
  "compilerOptions": {
    "rootDir": "./src",
    "outDir": "./dist",
    "module": "ESNext"
  }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;It works the same as the flag &lt;strong&gt;--module&lt;/strong&gt; of &lt;strong&gt;tsc&lt;/strong&gt;. You can compile the code again and see that now it uses ES Modules in compiled JavaScript code:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;dist/main.js&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="c1"&gt;// ...&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;createQuestioner&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="s2"&gt;./createQuestioner&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;greeting&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="s2"&gt;./greeting&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="c1"&gt;// ...&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  target
&lt;/h2&gt;

&lt;p&gt;The next important option of the TypeScript compiler is called &lt;strong&gt;target&lt;/strong&gt;. You may notice that when we created &lt;strong&gt;tsconfig.json&lt;/strong&gt; by command &lt;code&gt;tsc --init&lt;/code&gt; the option &lt;strong&gt;target&lt;/strong&gt; has already been set with value &lt;strong&gt;es5&lt;/strong&gt; in the configuration file. &lt;/p&gt;

&lt;p&gt;It means that TypeScript will compile the code to JavaScript code of version ES5. In other words, this compiled code can be executed by the browser or Node with a version that supports a version of JavaScript (ECMAScript) that is no more than ES5. So, if your environment where you need to run your application (some specific version of web browser or Node) doesn't support modern features of JavaScript, you should set option &lt;strong&gt;target&lt;/strong&gt; with the version of JavaScript that is supported by this environment.&lt;/p&gt;

&lt;p&gt;In practice if your environment is a Web browser, i.e. you work on the Front End project, you probably will use value &lt;strong&gt;es2015&lt;/strong&gt; of option &lt;strong&gt;target&lt;/strong&gt;. Of course, if you don't have some specific web browser and you need to run JavaScript with version &lt;strong&gt;ES3&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;For the Node, there is information &lt;a href="https://github.com/microsoft/TypeScript/wiki/Node-Target-Mapping" rel="noopener noreferrer"&gt;on GitHub&lt;/a&gt; with recommendations on what &lt;strong&gt;tsconfig.json&lt;/strong&gt; settings to use.&lt;/p&gt;

&lt;p&gt;A table with information about which &lt;strong&gt;target&lt;/strong&gt; to use for a specific Node version:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;version&lt;/th&gt;
&lt;th&gt;target&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;16&lt;/td&gt;
&lt;td&gt;ES2021&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;14&lt;/td&gt;
&lt;td&gt;ES2020&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;12&lt;/td&gt;
&lt;td&gt;ES2019&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;10&lt;/td&gt;
&lt;td&gt;ES2018&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;8&lt;/td&gt;
&lt;td&gt;ES2017&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;Also, check out the project &lt;a href="https://node.green" rel="noopener noreferrer"&gt;node.green&lt;/a&gt; that contains information about Node.js ECMAScript compatibility.&lt;/p&gt;

&lt;h3&gt;
  
  
  Example
&lt;/h3&gt;

&lt;p&gt;In our code example in file &lt;strong&gt;main.ts&lt;/strong&gt; we use async/await construction to manage asynchronous code. async/await construction have been available since the ES2017 version of &lt;a href="https://byte.ski/notes/ECMAScript" rel="noopener noreferrer"&gt;ECMAScript&lt;/a&gt;. &lt;/p&gt;

&lt;p&gt;How it looks like in &lt;strong&gt;main.ts&lt;/strong&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="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;firstName&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nx"&gt;questioner&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;ask&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Type your first name: &lt;/span&gt;&lt;span class="dl"&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;username&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nx"&gt;questioner&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;ask&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Type your username: &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;Set the option &lt;strong&gt;target&lt;/strong&gt; to &lt;strong&gt;ES2015&lt;/strong&gt;:&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;"compilerOptions"&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;"rootDir"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"./src"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="nl"&gt;"outDir"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"./dist"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="nl"&gt;"target"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"ES2015"&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;And compile the code:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;tsc
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now, open the file &lt;strong&gt;dist/main.js&lt;/strong&gt; in the editor. You will see that where in our code was async/await construction, there is now something else:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="c1"&gt;// ...&lt;/span&gt;
&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;main&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nf"&gt;__awaiter&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="k"&gt;void&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="k"&gt;void&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt;&lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;try&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;questioner&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;createQuestioner&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;firstName&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;yield&lt;/span&gt; &lt;span class="nx"&gt;questioner&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;ask&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Type your first name: &lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// async await??&lt;/span&gt;
            &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;username&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;yield&lt;/span&gt; &lt;span class="nx"&gt;questioner&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;ask&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Type your username: &lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
            &lt;span class="nf"&gt;greeting&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;firstName&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;username&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
            &lt;span class="nx"&gt;questioner&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;finishUp&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
        &lt;span class="p"&gt;}&lt;/span&gt;
        &lt;span class="k"&gt;catch &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;e&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
            &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;error&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;e&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;span class="c1"&gt;// ...&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The reason why compiled code doesn't have async/await that we used in &lt;strong&gt;main.ts&lt;/strong&gt; is that the code was compiled into the version of JavaScript that can be executed by Web browser or Node that doesn't support async/await construction.&lt;/p&gt;

&lt;p&gt;Now, set the option &lt;strong&gt;target&lt;/strong&gt; to value &lt;strong&gt;ES2017&lt;/strong&gt; (or any version that is more than ES2017) and run &lt;code&gt;tsc&lt;/code&gt;. Open file &lt;strong&gt;dist/main.js&lt;/strong&gt; again. You will see:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="c1"&gt;// ...&lt;/span&gt;
&lt;span class="k"&gt;async&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;main&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;try&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;questioner&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;createQuestioner&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;firstName&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nx"&gt;questioner&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;ask&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Type your first name: &lt;/span&gt;&lt;span class="dl"&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;username&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nx"&gt;questioner&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;ask&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Type your username: &lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
        &lt;span class="nf"&gt;greeting&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;firstName&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;username&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
        &lt;span class="nx"&gt;questioner&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;finishUp&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="k"&gt;catch &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;e&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;error&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;e&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="c1"&gt;// ...&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;&lt;em&gt;Do you like the material? Please, &lt;a href="https://byte.ski/newsletter" rel="noopener noreferrer"&gt;subscribe to my email newsletter&lt;/a&gt; to stay up to date.&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://byte.ski/newsletter" rel="noopener noreferrer"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ffld1yqfgvgz2dgcpho0x.png" alt="subscribe" width="545" height="153"&gt;&lt;/a&gt;&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>typescript</category>
    </item>
    <item>
      <title>Getting Started With TypeScript Compiler (tsc)</title>
      <dc:creator>Max Kovalevsky</dc:creator>
      <pubDate>Sun, 16 May 2021 18:27:00 +0000</pubDate>
      <link>https://dev.to/kovalevsky/getting-started-with-typescript-compiler-tsc-34h2</link>
      <guid>https://dev.to/kovalevsky/getting-started-with-typescript-compiler-tsc-34h2</guid>
      <description>&lt;p&gt;This post is part of series and &lt;a href="https://byte.ski/typescript-book" rel="noopener noreferrer"&gt;book about TypeScript&lt;/a&gt;. It will guide you from scratch to writing full TypeScript applications on Back End and Front End. The series is available as &lt;strong&gt;PDF eBook&lt;/strong&gt; for &lt;strong&gt;free&lt;/strong&gt; to &lt;strong&gt;everyone&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://byte.ski/typescript-book" rel="noopener noreferrer"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fidg3cmsrhuu0jqx5bulp.png" alt="TypeScript Book (PDF)" width="409" height="117"&gt;&lt;/a&gt;   &lt;/p&gt;

&lt;p&gt;From the previous post &lt;a href="https://byte.ski/blog/article/typescript-what-is-all-about-and-why-should-you-use-it" rel="noopener noreferrer"&gt;TypeScript - What Is All About And Why Should You Use It?&lt;/a&gt; we know that TypeScript is a superset of JavaScript and programming language. But how can you use it? If you worked with JavaScript in Front End you know that your code is executing by &lt;a href="https://byte.ski/notes/Web-browser" rel="noopener noreferrer"&gt;Web browser&lt;/a&gt;. In Back End, your code is running by &lt;a href="https://byte.ski/notes/Node" rel="noopener noreferrer"&gt;Node&lt;/a&gt;. What about TypeScript?&lt;/p&gt;

&lt;p&gt;The thing is that TypeScript is provided with a special program, tool - compiler. A compiler is a program that compiles (transforms) one code to another.&lt;/p&gt;

&lt;h2&gt;
  
  
  What is TypeScript compiler?
&lt;/h2&gt;

&lt;p&gt;As we mentioned before, TypeScript compiler is a tool, or program, that &lt;em&gt;compiles&lt;/em&gt; (transforms) &lt;strong&gt;valid&lt;/strong&gt; TypeScript code into JavaScript code. It is also a type checker and it validates TypeScript code &lt;/p&gt;

&lt;p&gt;When you install TypeScript by &lt;a href="https://byte.ski/notes/npm" rel="noopener noreferrer"&gt;npm&lt;/a&gt; or &lt;a href="https://byte.ski/notes/Yarn" rel="noopener noreferrer"&gt;Yarn&lt;/a&gt; globally, the TypeScript compiler will be available on your local machine as a command &lt;strong&gt;tsc&lt;/strong&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;npm i -g typescript
tsc --version
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;TypeScript compiler has many flags and options to use in various types of projects. You can use it in Front End project with libraries like &lt;a href="https://byte.ski/notes/React" rel="noopener noreferrer"&gt;React&lt;/a&gt;. In &lt;a href="https://byte.ski/notes/Angular" rel="noopener noreferrer"&gt;Angular&lt;/a&gt; it is already used inside Angular's toolchain. You can also use &lt;strong&gt;tsc&lt;/strong&gt; in Back End development with &lt;a href="https://byte.ski/notes/Node" rel="noopener noreferrer"&gt;Node&lt;/a&gt;. Here is the post about &lt;a href="https://byte.ski/blog/article/setup-simple-workflow-to-write-node-typeScript-application-in-live-reload" rel="noopener noreferrer"&gt;How To Setup Node TypeScript Workflow&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;In this post, we will explore how to use &lt;strong&gt;tsc&lt;/strong&gt; with a few general options.&lt;/p&gt;

&lt;h2&gt;
  
  
  Usage
&lt;/h2&gt;

&lt;p&gt;We will use &lt;strong&gt;tsc&lt;/strong&gt; with a simple example. It is an &lt;a href="https://byte.ski/notes/command-line-interface" rel="noopener noreferrer"&gt;command-line interface&lt;/a&gt; app that asks us to type our first name and username and then greetings us. It is a Node.js application and we will execute it by Node. If you didn't install Node or you have Node with a version that is lower than 15 on your local machine, check out the post &lt;a href="https://byte.ski/blog/article/how-to-install-or-update-node-by-using-nvm" rel="noopener noreferrer"&gt;How To Install or Update Node by Using nvm (Node Version Manager)&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;If you don't know how to run a TypeScript compiler, I recommend checking out the post &lt;a href="https://byte.ski/blog/article/detecting-errors-before-running-code-with-typescript" rel="noopener noreferrer"&gt;Detecting Errors Before Running Code With TypeScript&lt;/a&gt;. We will use pretty much the same example as in that post but with small differences.&lt;/p&gt;

&lt;p&gt;Let's create a folder called &lt;strong&gt;tsc-intro&lt;/strong&gt; or whatever you want. First of all, create two helper modules (files) with the following code:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;createQuestioner.ts&lt;/strong&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;createInterface&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="s2"&gt;readline&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;promisify&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="s2"&gt;util&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="kr"&gt;interface&lt;/span&gt; &lt;span class="nx"&gt;Questioner&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nf"&gt;ask&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;text&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="nb"&gt;Promise&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="kr"&gt;string&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nf"&gt;finishUp&lt;/span&gt;&lt;span class="p"&gt;():&lt;/span&gt; &lt;span class="k"&gt;void&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;createQuestioner&lt;/span&gt;&lt;span class="p"&gt;():&lt;/span&gt; &lt;span class="nx"&gt;Questioner&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;rlInterface&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;createInterface&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;
    &lt;span class="na"&gt;input&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;process&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;stdin&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="na"&gt;output&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;process&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;stdout&lt;/span&gt;&lt;span class="p"&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;ask&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;promisify&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;rlInterface&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;question&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nf"&gt;bind&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;rlInterface&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;finishUp&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="nx"&gt;rlInterface&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;close&lt;/span&gt;&lt;span class="p"&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="nx"&gt;ask&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="nx"&gt;finishUp&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="p"&gt;};&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;greeting.ts&lt;/strong&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;export&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;greeting&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;firstName&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="nx"&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="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;`Hello, &lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;firstName&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt; (@&lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;username&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&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;These two functions will be used in &lt;strong&gt;main&lt;/strong&gt; module of our app which is an entry point. Let's create file &lt;strong&gt;main.ts&lt;/strong&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;createQuestioner&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="s2"&gt;./createQuestioner&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;greeting&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="s2"&gt;./greeting&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="k"&gt;async&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;main&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;try&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;questioner&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;createQuestioner&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;firstName&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nx"&gt;questioner&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;ask&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Type your first name: &lt;/span&gt;&lt;span class="dl"&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;username&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nx"&gt;questioner&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;ask&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Type your username: &lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

    &lt;span class="nf"&gt;greeting&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;firstName&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;username&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

    &lt;span class="nx"&gt;questioner&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;finishUp&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;catch &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;e&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;error&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;e&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="nf"&gt;main&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Also, you need to install Type Declarations of Node as a dev dependency in your local project. If you don't know about Type Declarations, check about the post &lt;a href="https://byte.ski/blog/article/what-are-type-declaration-files-in-typescript" rel="noopener noreferrer"&gt;What Are Type Declaration Files In TypeScript&lt;/a&gt;.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;npm install --save-dev @types/node
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Don't focus on the code too much. It's just an example of TypeScript code but first of all, we need to focus on using the TypeScript compiler. &lt;/p&gt;

&lt;p&gt;Alright. Now it's time to use the TypeScript compiler to &lt;em&gt;transform&lt;/em&gt; the TypeScript code into JavaScript code that we will execute by Node:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;tsc main.ts
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Great! Now you have compiled file &lt;strong&gt;main.js&lt;/strong&gt; that you can execute by command:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;node main.js
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You should have noticed that there are also new files that we didn't create in our folder: &lt;strong&gt;createQuestioner.js&lt;/strong&gt; and &lt;strong&gt;greeting.js&lt;/strong&gt;. Although we compile only file &lt;strong&gt;main.ts&lt;/strong&gt;, TypeScript also compiles all modules that were used in &lt;strong&gt;main.ts&lt;/strong&gt; - greeting.ts and createQuestioner.ts. The code from these modules will be executed by Node when we will run it by &lt;code&gt;node main.js&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;If you are worked with Node.js before you may noticed that we imported modules in &lt;strong&gt;main.ts&lt;/strong&gt; by using &lt;code&gt;import smth from 'module'&lt;/code&gt; (&lt;a href="https://byte.ski/notes/ES-Modules" rel="noopener noreferrer"&gt;ES Modules&lt;/a&gt;) not &lt;code&gt;const smth = require('module')&lt;/code&gt; (&lt;a href="https://byte.ski/notes/CommonJS-Modules" rel="noopener noreferrer"&gt;CommonJS Modules&lt;/a&gt;). Of course, modern Node.js can work with ECMAScript modules. However, CommonJS Modules are still a general way to import and export modules in Node.&lt;/p&gt;

&lt;p&gt;So, how does it works? The thing is that TypeScript by default compiles code that we wrote using ECMAScript modules into the JavaScript code with CommonJS Modules. Let's look into compiled files:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;createQuestioner.js&lt;/strong&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;use strict&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="nx"&gt;exports&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;__esModule&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="nx"&gt;exports&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;createQuestioner&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;void&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="kd"&gt;var&lt;/span&gt; &lt;span class="nx"&gt;readline_1&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;require&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;readline&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="kd"&gt;var&lt;/span&gt; &lt;span class="nx"&gt;util_1&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;require&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;util&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;createQuestioner&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="kd"&gt;var&lt;/span&gt; &lt;span class="nx"&gt;rlInterface&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;readline_1&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;createInterface&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;
        &lt;span class="na"&gt;input&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;process&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;stdin&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="na"&gt;output&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;process&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;stdout&lt;/span&gt;
    &lt;span class="p"&gt;});&lt;/span&gt;
    &lt;span class="kd"&gt;var&lt;/span&gt; &lt;span class="nx"&gt;ask&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;util_1&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;promisify&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;rlInterface&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;question&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nf"&gt;bind&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;rlInterface&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="kd"&gt;var&lt;/span&gt; &lt;span class="nx"&gt;finishUp&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;function &lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="nx"&gt;rlInterface&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;close&lt;/span&gt;&lt;span class="p"&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="na"&gt;ask&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;ask&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="na"&gt;finishUp&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;finishUp&lt;/span&gt;
    &lt;span class="p"&gt;};&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="nx"&gt;exports&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;createQuestioner&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;createQuestioner&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;greeting.js&lt;/strong&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;use strict&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="nx"&gt;exports&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;__esModule&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="nx"&gt;exports&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;greeting&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;void&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;greeting&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;firstName&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;username&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Hello, &lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="nx"&gt;firstName&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt; (@&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="nx"&gt;username&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;)!&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="nx"&gt;exports&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;greeting&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;greeting&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;No code uses ECMAScript modules! In &lt;strong&gt;createQuestioner.js&lt;/strong&gt; on line 20 the function &lt;em&gt;createQuestioner&lt;/em&gt; is exporting by using CommonJS &lt;code&gt;exports.greeting = greeting;&lt;/code&gt;. The same in &lt;strong&gt;greeting.js&lt;/strong&gt;: on line 7 you will see the code &lt;code&gt;exports.greeting = greeting;&lt;/code&gt; which is CommonJS.&lt;/p&gt;

&lt;p&gt;Okay, the exporting is sorted out. What about importing modules?&lt;/p&gt;

&lt;p&gt;Let's look into the file &lt;strong&gt;main.js&lt;/strong&gt;:&lt;/p&gt;

&lt;p&gt;&lt;em&gt;The file is quite large so I cut the code that is not important for us right now&lt;/em&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;use strict&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="c1"&gt;// some code here&lt;/span&gt;
&lt;span class="nx"&gt;exports&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;__esModule&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="kd"&gt;var&lt;/span&gt; &lt;span class="nx"&gt;createQuestioner_1&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;require&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;./createQuestioner&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="kd"&gt;var&lt;/span&gt; &lt;span class="nx"&gt;greeting_1&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;require&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;./greeting&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;main&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nf"&gt;__awaiter&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="k"&gt;void&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="k"&gt;void&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nf"&gt;function &lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="kd"&gt;var&lt;/span&gt; &lt;span class="nx"&gt;questioner&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;firstName&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;username&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;e_1&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nf"&gt;__generator&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nf"&gt;function &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;_a&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
            &lt;span class="k"&gt;switch &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;_a&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;label&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
                &lt;span class="k"&gt;case&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
                    &lt;span class="nx"&gt;_a&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;trys&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;push&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="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;4&lt;/span&gt;&lt;span class="p"&gt;]);&lt;/span&gt;
                    &lt;span class="nx"&gt;questioner&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;createQuestioner_1&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;createQuestioner&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="mi"&gt;4&lt;/span&gt; &lt;span class="cm"&gt;/*yield*/&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;questioner&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;ask&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Type your first name: &lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)];&lt;/span&gt;
                &lt;span class="k"&gt;case&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
                    &lt;span class="nx"&gt;firstName&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;_a&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;sent&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="mi"&gt;4&lt;/span&gt; &lt;span class="cm"&gt;/*yield*/&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;questioner&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;ask&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Type your username: &lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)];&lt;/span&gt;
                &lt;span class="k"&gt;case&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
                    &lt;span class="nx"&gt;username&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;_a&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;sent&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
                    &lt;span class="nx"&gt;greeting_1&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;greeting&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;firstName&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;username&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
                    &lt;span class="nx"&gt;questioner&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;finishUp&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="mi"&gt;3&lt;/span&gt; &lt;span class="cm"&gt;/*break*/&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;4&lt;/span&gt;&lt;span class="p"&gt;];&lt;/span&gt;
                &lt;span class="k"&gt;case&lt;/span&gt; &lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
                    &lt;span class="nx"&gt;e_1&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;_a&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;sent&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
                    &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;error&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;e_1&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="mi"&gt;3&lt;/span&gt; &lt;span class="cm"&gt;/*break*/&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;4&lt;/span&gt;&lt;span class="p"&gt;];&lt;/span&gt;
                &lt;span class="k"&gt;case&lt;/span&gt; &lt;span class="mi"&gt;4&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="mi"&gt;2&lt;/span&gt; &lt;span class="cm"&gt;/*return*/&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;span class="p"&gt;}&lt;/span&gt;
&lt;span class="nf"&gt;main&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;On lines 4 and 5 (in the file - 39 and 40), you will see that modules &lt;strong&gt;greeting&lt;/strong&gt; and &lt;strong&gt;createQuestioner&lt;/strong&gt; is imported by CommonJS modules. &lt;/p&gt;

&lt;p&gt;The great thing is that TypeScript is a very configurable tool and we can compile TypeScript to the JavaScript code that uses ECMAScript Modules!&lt;/p&gt;

&lt;p&gt;All we have to do is to use option &lt;strong&gt;--module&lt;/strong&gt; with value &lt;strong&gt;ESNext&lt;/strong&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;tsc --module ESNext main.ts
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The value &lt;strong&gt;ESNext&lt;/strong&gt; means that TypeScript will compile code into the latest version of ECMAScript standard. For the purpose to use ECMAScript modules in compiled code it works for us.&lt;/p&gt;

&lt;p&gt;Let's look into compiled file &lt;strong&gt;main.js&lt;/strong&gt; again:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// ...
import { createQuestioner } from "./createQuestioner";
import { greeting } from "./greeting";
function main() {
    // ...
}
main();
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Great! We have the code with imports that we need. It's time to execute thins code by Node:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;node main.js
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;And... It fails. Node tells us that we need to specify parameter &lt;strong&gt;type&lt;/strong&gt; with value &lt;strong&gt;module&lt;/strong&gt; in file &lt;strong&gt;package.json&lt;/strong&gt;. First of all, we need to create package.json in our folder:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;npm init -y
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;And then add the parameter in the file:&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;"devDependencies"&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;"@types/node"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"^15.3.0"&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;"name"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"tsc-intro"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"version"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"1.0.0"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"main"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"main.js"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"scripts"&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;"test"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"echo &lt;/span&gt;&lt;span class="se"&gt;\"&lt;/span&gt;&lt;span class="s2"&gt;Error: no test specified&lt;/span&gt;&lt;span class="se"&gt;\"&lt;/span&gt;&lt;span class="s2"&gt; &amp;amp;&amp;amp; exit 1"&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;"keywords"&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;"author"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&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;"license"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"ISC"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"description"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&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;"type"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"module"&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;Try to run main.js again:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;node main.js
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;It fails again!&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Error [ERR_MODULE_NOT_FOUND]: Cannot find module 'tsc-intro/createQuestioner' imported from /tsc-intro/main.js
Did you mean to import ../createQuestioner.js?
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The new problem is that Node can't understand modules that are imported without file extensions &lt;strong&gt;.js&lt;/strong&gt;. To solve this just use the special Node option for now:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;node --es-module-specifier-resolution=node main.js
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Separating files into different folders
&lt;/h2&gt;

&lt;p&gt;Everything works fine. But we have some mess in a folder. There are files that we wrote in TypeScript and also compiled JavaScript files. Let's clean the folder.&lt;/p&gt;

&lt;p&gt;We can manage it by separating files into different folders. One is for source code that we write and the second one is for output code that will be executed by Node. We will use the TypeScript compiler for that purpose.&lt;/p&gt;

&lt;p&gt;Create the folder &lt;strong&gt;/src&lt;/strong&gt; and put all &lt;strong&gt;.ts&lt;/strong&gt; files there:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;mkdir src
mv *.ts src/
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Also, remove all compiled &lt;strong&gt;.js&lt;/strong&gt; files in the root folder:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;rm *.js
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;All we have to do is run TypeScript compiled with special options &lt;strong&gt;outDir&lt;/strong&gt; which is a path to the folder there should be compiled JavaScript files.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;tsc --module ESNext --outDir "./dist" src/main.ts
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Watch mode
&lt;/h2&gt;

&lt;p&gt;Most of the time, we need to quickly change something in the code and see the result of the changes right now. Use this whole &lt;strong&gt;tsc&lt;/strong&gt; command whenever we need to re-compile our project is a bit uncomfortable. We can use option &lt;strong&gt;--watch&lt;/strong&gt; that re-run TypeScript compiler every time when files changes in &lt;strong&gt;/src&lt;/strong&gt; folder.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;tsc --module ESNext --outDir "./dist" --watch src/main.ts
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Using &lt;strong&gt;watch mode&lt;/strong&gt; is not enough for developing Node.js application because we also need to re-run Node after changes in the code. Check out the post &lt;a href="https://byte.ski/blog/article/setup-simple-workflow-to-write-node-typeScript-application-in-live-reload" rel="noopener noreferrer"&gt;How To Setup Simple Workflow To Write Node TypeScript Application In Live Reload&lt;/a&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  Checking code without compilation
&lt;/h2&gt;

&lt;p&gt;Another aspect of using TypeScript in modern Front End or Back End development is that we do not always need to compile TypeScript code into JavaScript code by using &lt;strong&gt;tsc&lt;/strong&gt;. We can also use &lt;a href="https://byte.ski/notes/Babel" rel="noopener noreferrer"&gt;Babel&lt;/a&gt; for that purpose.&lt;/p&gt;

&lt;p&gt;Compiling TypeScript or JavaScript code can be a quite long process. If you need to just check your types and validate your code you can use TypeScript without compilation by this command:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;tsc --noEmit ./src/main.ts
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Conclusions
&lt;/h2&gt;

&lt;p&gt;In this post, we learned how to use TypeScript compiler with just several general options. We configured &lt;strong&gt;tsc&lt;/strong&gt; by using command's flags but it also can be managed by using configuration file - &lt;strong&gt;tsconfig.json&lt;/strong&gt;. In the next post, we will see how to configure &lt;strong&gt;tsc&lt;/strong&gt; by &lt;strong&gt;tsconfig.json&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;Do you like the material? Please, &lt;a href="https://byte.ski/newsletter" rel="noopener noreferrer"&gt;subscribe to my email newsletter&lt;/a&gt; to stay up to date.&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://byte.ski/newsletter" rel="noopener noreferrer"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ffld1yqfgvgz2dgcpho0x.png" alt="subscribe" width="545" height="153"&gt;&lt;/a&gt;&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>typescript</category>
    </item>
    <item>
      <title>Setup Simple Workflow To Write Node TypeScript Application In Live Reload (Nodemon, ts-node)</title>
      <dc:creator>Max Kovalevsky</dc:creator>
      <pubDate>Wed, 12 May 2021 19:18:34 +0000</pubDate>
      <link>https://dev.to/kovalevsky/setup-simple-workflow-to-write-node-typescript-application-in-live-reload-3aom</link>
      <guid>https://dev.to/kovalevsky/setup-simple-workflow-to-write-node-typescript-application-in-live-reload-3aom</guid>
      <description>&lt;p&gt;This post is part of series and &lt;a href="https://byte.ski/typescript-book" rel="noopener noreferrer"&gt;book about TypeScript&lt;/a&gt;. It will guide you from scratch to writing full TypeScript applications on Back End and Front End. The series is available as &lt;strong&gt;PDF eBook&lt;/strong&gt; for &lt;strong&gt;free&lt;/strong&gt; to &lt;strong&gt;everyone&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://byte.ski/typescript-book" rel="noopener noreferrer"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fidg3cmsrhuu0jqx5bulp.png" alt="TypeScript Book (PDF)" width="409" height="117"&gt;&lt;/a&gt;   &lt;/p&gt;

&lt;p&gt;In this post, we will learn how to set up a Node project with TypeScript. It is not based on any framework or library like Fastify, Express, Nest, etc. Let's say you wanna build just a command-line application by using TypeScript and Node.&lt;/p&gt;

&lt;p&gt;First of all, you need to install TypeScript on your computer. Install it by &lt;a href="https://byte.ski/notes/npm" rel="noopener noreferrer"&gt;npm&lt;/a&gt; or &lt;a href="https://byte.ski/notes/Yarn" rel="noopener noreferrer"&gt;Yarn&lt;/a&gt; globally.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;npm i -g typescript
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;I'm sure you already installed &lt;a href="https://byte.ski/notes/Node" rel="noopener noreferrer"&gt;Node&lt;/a&gt; on your computer but maybe you need to update your version. If so, check out the post about &lt;a href="https://byte.ski/blog/article/how-to-install-or-update-node-by-using-nvm" rel="noopener noreferrer"&gt;How To Install or Update Node by Using nvm (Node Version Manager)&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Okay, now let's create a project's folder with name whatever you want (I name it as &lt;strong&gt;node-ts-setup-example&lt;/strong&gt;). Open this folder in Terminal and your editor (I use &lt;a href="https://byte.ski/notes/Visual-Studio-Code" rel="noopener noreferrer"&gt;Visual Studio Code&lt;/a&gt;).&lt;/p&gt;

&lt;p&gt;Initialize the project by npm command:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;npm init -y
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Our project as an example will be simple - it is a command-line app that asks users to type their name in the Terminal and then prints greetings with this name.&lt;/p&gt;

&lt;p&gt;Let's create a first file of the project - &lt;strong&gt;main.ts&lt;/strong&gt;. Just put there very basic &lt;a href="https://byte.ski/notes/TypeScript" rel="noopener noreferrer"&gt;TypeScript&lt;/a&gt; code like this:&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;createInterface&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="s2"&gt;readline&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;promisify&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="s2"&gt;util&lt;/span&gt;&lt;span class="dl"&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;rlInterface&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;createInterface&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;
  &lt;span class="na"&gt;input&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;process&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;stdin&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="na"&gt;output&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;process&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;stdout&lt;/span&gt;&lt;span class="p"&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;question&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;promisify&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;rlInterface&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;question&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nf"&gt;bind&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;rlInterface&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;greeting&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;name&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;unknown&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;`Hello, &lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;name&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;!`&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="k"&gt;async&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;main&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;try&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;name&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nf"&gt;question&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Type your name: &lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

    &lt;span class="nf"&gt;greeting&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;name&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

    &lt;span class="nx"&gt;rlInterface&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;close&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;catch &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;e&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;error&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;e&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="nf"&gt;main&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now let's try to compile this file by using the TypeScript compiler:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;tsc main.ts
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;As you may have noticed TypeScript tells us that we need to install Type Declaration for modules of &lt;a href="https://byte.ski/notes/Node" rel="noopener noreferrer"&gt;Node&lt;/a&gt; that we use - &lt;strong&gt;readline&lt;/strong&gt; and &lt;strong&gt;util&lt;/strong&gt;. If you are not familiar with Type Declarations check out the post &lt;a href="https://byte.ski/blog/article/what-are-type-declaration-files-in-typescript" rel="noopener noreferrer"&gt;What Are Type Declaration Files In TypeScript?&lt;/a&gt;. For now, let's just install these Type Declarations by &lt;a href="https://byte.ski/notes/npm" rel="noopener noreferrer"&gt;npm&lt;/a&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;npm install --save-dev @types/node
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Try to compile &lt;strong&gt;main.ts&lt;/strong&gt; again:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;tsc main.ts
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Great! The file was successfully compiled. Let's run it by &lt;a href="https://byte.ski/notes/Node" rel="noopener noreferrer"&gt;Node&lt;/a&gt; and type our name to see greetings:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;node main.js
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Awesome. But what if we need to change our code a bit? When we change that we need to compile this file again and run it by Node. It would be great if our code will be automatically compiled and executed after changing. We can automate the process by running TypeScript compiler in &lt;strong&gt;watch mode&lt;/strong&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;tsc main.ts -w
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;So now TypeScript compiler automatically compiles &lt;strong&gt;main.ts&lt;/strong&gt; into JavaScript code. But what about executing this? Well, TypeScript can't execute the code, only compile it.&lt;/p&gt;

&lt;p&gt;We can set up the project to automate our development process. Let's start with TypeScript configuration. We need to create TypeScript configuration file in our project. We can use a special command that generates a configuration file with default settings:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;tsc --init
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;It generated the file &lt;strong&gt;tsconfig.json&lt;/strong&gt;. If you open this file you will see there are many options and parameters. I will write about it more in the next posts. All we need to do is focus on parameters &lt;strong&gt;outDir&lt;/strong&gt; and &lt;strong&gt;rootDir&lt;/strong&gt;. Uncomment these options in the &lt;strong&gt;tsconfig.json&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;outDir&lt;/strong&gt; is the path to folder where will be compiled from TypeScript to JavaScript code.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;rootDir&lt;/strong&gt; is the path to folder where are our TypeScript source code of the app. In our case - file &lt;strong&gt;main.ts&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;Specify the options with values:&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="err"&gt;...&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="nl"&gt;"outDir"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"./dist"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="nl"&gt;"rootDir"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"./src"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="err"&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;Also we need to uncomment parameter &lt;strong&gt;moduleResolution&lt;/strong&gt; with value &lt;strong&gt;node&lt;/strong&gt;:&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="nl"&gt;"moduleResolution"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"node"&lt;/span&gt;&lt;span class="err"&gt;,&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="err"&gt;/*&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="err"&gt;Specify&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="err"&gt;module&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="err"&gt;resolution&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="err"&gt;strategy:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="err"&gt;'node'&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="err"&gt;(Node.js)&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="err"&gt;or&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="err"&gt;'classic'&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="err"&gt;(TypeScript&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="err"&gt;pre&lt;/span&gt;&lt;span class="mf"&gt;-1.6&lt;/span&gt;&lt;span class="err"&gt;).&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="err"&gt;*/&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Create folder &lt;strong&gt;/src&lt;/strong&gt; and move &lt;strong&gt;main.ts&lt;/strong&gt; there.&lt;/p&gt;

&lt;p&gt;Alright. We configured TypeScript for our project. Now we have to configure &lt;a href="https://byte.ski/notes/Node" rel="noopener noreferrer"&gt;Node&lt;/a&gt; to execute our code in &lt;strong&gt;watch&lt;/strong&gt; mode.&lt;/p&gt;

&lt;p&gt;We need to install a few dev dependencies - &lt;a href="https://byte.ski/notes/ts-node" rel="noopener noreferrer"&gt;ts-node&lt;/a&gt; and &lt;a href="https://byte.ski/notes/nodemon" rel="noopener noreferrer"&gt;nodemon&lt;/a&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;npm i -D ts-node nodemon
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;ts-node&lt;/strong&gt; is a tool that executes code that is written in TypeScript as if it is written in JavaScript. I mean, you can perceive this as running &lt;a href="https://byte.ski/notes/Node" rel="noopener noreferrer"&gt;Node&lt;/a&gt; but for TypeScript files. You can also use &lt;strong&gt;ts-node&lt;/strong&gt; as a REPL to execute the code without files.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;nodemon&lt;/strong&gt; is a tool that restarts your Node application when some file changes. It really helps in developing because you don't need to re-run &lt;a href="https://byte.ski/notes/Node" rel="noopener noreferrer"&gt;Node&lt;/a&gt; if you change code in your application.&lt;/p&gt;

&lt;p&gt;Now let's specify section &lt;strong&gt;scripts&lt;/strong&gt; in &lt;strong&gt;package.json&lt;/strong&gt; file:&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="err"&gt;...&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="nl"&gt;"scripts"&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;"dev"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"nodemon -w src src/main.ts"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
        &lt;/span&gt;&lt;span class="nl"&gt;"start"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"node dist/main.js"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
        &lt;/span&gt;&lt;span class="nl"&gt;"build"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"tsc -p ."&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="err"&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;To run dev server use this command:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;npm run dev
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now if we change our code in &lt;strong&gt;main.ts&lt;/strong&gt; it automatically re-compiles and re-run Node to execute the code.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;Do you like the material? Please, &lt;a href="https://byte.ski/newsletter" rel="noopener noreferrer"&gt;subscribe to my email newsletter&lt;/a&gt; to stay up to date.&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://byte.ski/newsletter" rel="noopener noreferrer"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ffld1yqfgvgz2dgcpho0x.png" alt="subscribe" width="545" height="153"&gt;&lt;/a&gt;&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>typescript</category>
      <category>node</category>
    </item>
    <item>
      <title>What Are Type Declaration Files In TypeScript?</title>
      <dc:creator>Max Kovalevsky</dc:creator>
      <pubDate>Tue, 11 May 2021 18:22:28 +0000</pubDate>
      <link>https://dev.to/kovalevsky/what-are-type-declaration-files-in-typescript-53dd</link>
      <guid>https://dev.to/kovalevsky/what-are-type-declaration-files-in-typescript-53dd</guid>
      <description>&lt;p&gt;This post is part of series and &lt;a href="https://byte.ski/typescript-book" rel="noopener noreferrer"&gt;book about TypeScript&lt;/a&gt;. It will guide you from scratch to writing full TypeScript applications on Back End and Front End. The series is available as &lt;strong&gt;PDF eBook&lt;/strong&gt; for &lt;strong&gt;free&lt;/strong&gt; to &lt;strong&gt;everyone&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://byte.ski/typescript-book" rel="noopener noreferrer"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fidg3cmsrhuu0jqx5bulp.png" alt="TypeScript Book (PDF)" width="409" height="117"&gt;&lt;/a&gt;  &lt;/p&gt;

&lt;p&gt;You probably have seen files with a file extension like &lt;em&gt;.d.ts&lt;/em&gt; in some JavaScript or TypeScript projects (libraries or frameworks) before and you wondered what are these files and what they are for. In TypeScript they are called Type Declaration files. Let's find out what is that practically.&lt;/p&gt;

&lt;p&gt;Let's create a simple example with TypeScript code. Create a folder with the name &lt;strong&gt;typescript-type-defs&lt;/strong&gt; or whatever name you want and then let's create a file called &lt;strong&gt;users-list.ts&lt;/strong&gt; there with code:&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;users&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;
  &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="na"&gt;id&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;1&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;John&lt;/span&gt;&lt;span class="dl"&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="s2"&gt;johnsmith11&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="na"&gt;age&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;55&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="na"&gt;level&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;23&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="na"&gt;id&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;2&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;C3PO&lt;/span&gt;&lt;span class="dl"&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="s2"&gt;iamnotrobot&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="na"&gt;age&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;112&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="na"&gt;level&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="p"&gt;},&lt;/span&gt;
&lt;span class="p"&gt;];&lt;/span&gt;

&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;NAME_FIELD_KEY&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kr"&gt;keyof&lt;/span&gt; &lt;span class="nx"&gt;User&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;name&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="kr"&gt;interface&lt;/span&gt; &lt;span class="nx"&gt;User&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;id&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="nl"&gt;name&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="nl"&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="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;age&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;span class="nl"&gt;level&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;span class="p"&gt;}&lt;/span&gt;

&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;getEntityField&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;Entity&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
  &lt;span class="nx"&gt;entities&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;Entity&lt;/span&gt;&lt;span class="p"&gt;[],&lt;/span&gt;
  &lt;span class="nx"&gt;fieldName&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kr"&gt;keyof&lt;/span&gt; &lt;span class="nx"&gt;Entity&lt;/span&gt;
&lt;span class="p"&gt;):&lt;/span&gt; &lt;span class="nx"&gt;unknown&lt;/span&gt;&lt;span class="p"&gt;[]&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;entities&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;map&lt;/span&gt;&lt;span class="p"&gt;((&lt;/span&gt;&lt;span class="nx"&gt;entity&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;entity&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;fieldName&lt;/span&gt;&lt;span class="p"&gt;]);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;getUsersName&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;users&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="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="k"&gt;return&lt;/span&gt; &lt;span class="nf"&gt;getEntityField&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;users&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;NAME_FIELD_KEY&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;as&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="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;result&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;getUsersName&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;users&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;result&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;What if need to use Interface User somewhere else? Not a problem, just add &lt;code&gt;export&lt;/code&gt; before interface:&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;export&lt;/span&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;id&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="nl"&gt;name&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="nl"&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="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;age&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;span class="nl"&gt;level&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;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You can import this interface from module &lt;strong&gt;users-list&lt;/strong&gt; in another module. However, sometimes we need to use this interface as a common thing between several modules. So, &lt;em&gt;exporting&lt;/em&gt; interface from one of these modules is not an option. We need to create a special file where we can specify Interface User and use it in modules.&lt;/p&gt;

&lt;p&gt;Create a file with name &lt;strong&gt;typings.d.ts&lt;/strong&gt; and moved interface User from file &lt;strong&gt;users-list.ts&lt;/strong&gt; into this new file:&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;export&lt;/span&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;id&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="nl"&gt;name&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="nl"&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="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;age&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;span class="nl"&gt;level&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;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now we need to use this interface in module &lt;strong&gt;users-list&lt;/strong&gt;. You can just import this interface from &lt;strong&gt;typings.d.ts&lt;/strong&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;User&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="s2"&gt;./typings&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="c1"&gt;// ...&lt;/span&gt;

&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;NAME_FIELD_KEY&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kr"&gt;keyof&lt;/span&gt; &lt;span class="nx"&gt;User&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;name&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="c1"&gt;// ...&lt;/span&gt;

&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;getUsersName&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;users&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="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="k"&gt;return&lt;/span&gt; &lt;span class="nf"&gt;getEntityField&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;users&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;NAME_FIELD_KEY&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;as&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;// ...&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Let's look at file &lt;strong&gt;typings.d.ts&lt;/strong&gt; more. In this file, you cannot write variables, functions, and other code of TypeScript/JavaScript. All you can write there is types or interfaces. You can only define types there and use them in any modules.&lt;/p&gt;

&lt;p&gt;Usually, you don't write types in &lt;strong&gt;.d.ts&lt;/strong&gt; but in &lt;strong&gt;.ts&lt;/strong&gt; files. However, &lt;strong&gt;.d.ts&lt;/strong&gt; files are used in projects that are packages or libraries and are originally written in JavaScript. If you have JavaScript library and you have to add an ability to use your library in TypeScript projects, so you need to create &lt;strong&gt;.d.ts&lt;/strong&gt; files. Another case is when you write your library in TypeScript but you ship it in compiled JavaScript code. In that case, you can automatically generate Type Declarations based on your TypeScript source code by using the TypeScript compiler (tsc).&lt;/p&gt;

&lt;p&gt;Here is an example based on &lt;strong&gt;users-list.ts&lt;/strong&gt;. Let's use &lt;strong&gt;tsc&lt;/strong&gt; to generate Type Declaration file:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;tsc users-list.ts --declaration
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;After that you will see a new file called &lt;strong&gt;users-list.d.ts&lt;/strong&gt; with the following code:&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;User&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="s2"&gt;./typings&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="kr"&gt;declare&lt;/span&gt; &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;NAME_FIELD_KEY&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kr"&gt;keyof&lt;/span&gt; &lt;span class="nx"&gt;User&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="kr"&gt;declare&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;getEntityField&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;Entity&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;entities&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;Entity&lt;/span&gt;&lt;span class="p"&gt;[],&lt;/span&gt; &lt;span class="nx"&gt;fieldName&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kr"&gt;keyof&lt;/span&gt; &lt;span class="nx"&gt;Entity&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt; &lt;span class="nx"&gt;unknown&lt;/span&gt;&lt;span class="p"&gt;[];&lt;/span&gt;
&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="kr"&gt;declare&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;getUsersName&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;users&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="kr"&gt;string&lt;/span&gt;&lt;span class="p"&gt;[];&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;So with that Type Declaration file, you provide an ability to work with your library's API and types to someone who uses your library in their project.&lt;/p&gt;

&lt;p&gt;There is a huge repository that contains type definitions for many libraries and packages - &lt;a href="https://github.com/DefinitelyTyped/DefinitelyTyped" rel="noopener noreferrer"&gt;DefinitelyTyped&lt;/a&gt;. You probably have installed &lt;a href="https://byte.ski/notes/npm" rel="noopener noreferrer"&gt;npm&lt;/a&gt; packages with names like "@types/*". The code of some of these packages is in this repository.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;Do you like the material? Please, &lt;a href="https://byte.ski/newsletter" rel="noopener noreferrer"&gt;subscribe to my email newsletter&lt;/a&gt; to stay up to date.&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://byte.ski/newsletter" rel="noopener noreferrer"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ffld1yqfgvgz2dgcpho0x.png" alt="subscribe" width="545" height="153"&gt;&lt;/a&gt;&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>typescript</category>
    </item>
    <item>
      <title>Detecting Errors Before Running Code With TypeScript</title>
      <dc:creator>Max Kovalevsky</dc:creator>
      <pubDate>Mon, 10 May 2021 18:25:06 +0000</pubDate>
      <link>https://dev.to/kovalevsky/detecting-errors-before-running-code-with-typescript-44e4</link>
      <guid>https://dev.to/kovalevsky/detecting-errors-before-running-code-with-typescript-44e4</guid>
      <description>&lt;p&gt;This post is part of series and &lt;a href="https://byte.ski/typescript-book" rel="noopener noreferrer"&gt;book about TypeScript&lt;/a&gt;. It will guide you from scratch to writing full TypeScript applications on Back End and Front End. The series is available as &lt;strong&gt;PDF eBook&lt;/strong&gt; for &lt;strong&gt;free&lt;/strong&gt; to &lt;strong&gt;everyone&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://byte.ski/typescript-book" rel="noopener noreferrer"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fidg3cmsrhuu0jqx5bulp.png" alt="TypeScript Book (PDF)" width="409" height="117"&gt;&lt;/a&gt;   &lt;/p&gt;

&lt;h2&gt;
  
  
  The problem
&lt;/h2&gt;

&lt;p&gt;In the &lt;a href="https://byte.ski/blog/article/typescript-what-is-all-about-and-why-should-you-use-it" rel="noopener noreferrer"&gt;previous post&lt;/a&gt; we talked about what is &lt;a href="https://byte.ski/notes/TypeScript" rel="noopener noreferrer"&gt;TypeScript&lt;/a&gt; and why should we use that. Now it's time to go to practice.&lt;/p&gt;

&lt;p&gt;We need to know how to start using &lt;a href="https://byte.ski/notes/TypeScript" rel="noopener noreferrer"&gt;TypeScript&lt;/a&gt; in our &lt;a href="https://byte.ski/notes/JavaScript" rel="noopener noreferrer"&gt;JavaScript&lt;/a&gt; project. In examples of this post series, I will use mostly code that written in &lt;a href="https://byte.ski/notes/Node" rel="noopener noreferrer"&gt;Node&lt;/a&gt; environment. It won't be any specific code that is understandable for only developers who worked with &lt;a href="https://byte.ski/notes/Node" rel="noopener noreferrer"&gt;Node&lt;/a&gt; before. Because this material is about TypeScript I want to specify more on TypeScript itself. &lt;/p&gt;

&lt;p&gt;Okay, let's start with an introduction to our first example. Here we have a very simple command-line application that works on &lt;a href="https://byte.ski/notes/Node" rel="noopener noreferrer"&gt;Node&lt;/a&gt;. This example consists of one file. Let name it &lt;strong&gt;sum.js&lt;/strong&gt;. When we execute this file by Node it will ask two questions in the Terminal - a value of argument X and Y. After typing these values the app will print the result of &lt;em&gt;X + Y&lt;/em&gt;.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;An example of this code is written with [[Node]]. If Node is not installed on your machine, check out the post about &lt;a href="https://byte.ski/blog/article/how-to-install-or-update-node-by-using-nvm" rel="noopener noreferrer"&gt;How To Install or Update Node by Using nvm (Node Version Manager)&lt;/a&gt;.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Look at the code:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;readline&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;require&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;readline&lt;/span&gt;&lt;span class="dl"&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;rlInterface&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;readline&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;createInterface&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;
  &lt;span class="na"&gt;input&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;process&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;stdin&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="na"&gt;output&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;process&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;stdout&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;span class="p"&gt;});&lt;/span&gt;

&lt;span class="c1"&gt;// there is a simplified version of util.promisify method&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;question&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;message&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="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Promise&lt;/span&gt;&lt;span class="p"&gt;((&lt;/span&gt;&lt;span class="nx"&gt;resolve&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="nx"&gt;rlInterface&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;question&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;message&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;data&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="nf"&gt;resolve&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;data&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;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;sum&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;a&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;b&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;a&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="nx"&gt;b&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="k"&gt;async&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;main&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;try&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;argX&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nf"&gt;question&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Type value of X: &lt;/span&gt;&lt;span class="dl"&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;argY&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nf"&gt;question&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Type value of Y: &lt;/span&gt;&lt;span class="dl"&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;result&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;sum&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;argX&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;argY&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

    &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;`Result: &lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;result&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;`&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

    &lt;span class="nx"&gt;rlInterface&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;close&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;catch &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;e&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;error&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;e&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="nf"&gt;main&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Don't focus on module &lt;em&gt;readline&lt;/em&gt;, methods &lt;em&gt;createInterface&lt;/em&gt; and &lt;em&gt;question&lt;/em&gt;. It's just a &lt;a href="https://byte.ski/notes/Node" rel="noopener noreferrer"&gt;Node&lt;/a&gt; specific code that allows us to take data that the user types in the Terminal. Let's focus on functions &lt;em&gt;sum&lt;/em&gt; and &lt;em&gt;main&lt;/em&gt;. The function &lt;em&gt;main&lt;/em&gt; is just an entry point of our small app.&lt;/p&gt;

&lt;p&gt;Alright. Now let's test our app that it works correctly. To run the app use this command (if you already in the same folder as file sum.js there):&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;node sum.js
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The app is asking you to type the value of parameters &lt;strong&gt;X&lt;/strong&gt; and &lt;strong&gt;Y&lt;/strong&gt;. Let it be 7 and 2. &lt;/p&gt;

&lt;p&gt;We expected that result will be 9 but the result is disappointed. The app prints:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;72
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;There is a &lt;strong&gt;bug&lt;/strong&gt;. The thing is that the value that function &lt;em&gt;question&lt;/em&gt; returns have type &lt;strong&gt;string&lt;/strong&gt;, not &lt;strong&gt;number&lt;/strong&gt; as it expected in function &lt;em&gt;sum&lt;/em&gt;.&lt;/p&gt;

&lt;p&gt;It is a typical problem with &lt;a href="https://byte.ski/notes/JavaScript" rel="noopener noreferrer"&gt;JavaScript&lt;/a&gt; type system. I would say, it is a JavaScript trademark. Probably, you could see memes and jokes about this problem.&lt;/p&gt;

&lt;p&gt;It's all perfectly fine, but how can we avoid this problem? Of course, you can change function &lt;em&gt;sum&lt;/em&gt; and do something like this (unary add operator):&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;sum&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;a&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;b&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt;&lt;span class="nx"&gt;a&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt;&lt;span class="nx"&gt;b&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;But don't you think that this looks like a bad solution? It seems like that we try to use a patch to hide a hole in the tearing jacket. Instead of this, we can put on a new jacket that won't have holes (or maybe less than the previous one) - &lt;a href="https://byte.ski/notes/TypeScript" rel="noopener noreferrer"&gt;TypeScript&lt;/a&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  The solution
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Installing TypeScript
&lt;/h3&gt;

&lt;p&gt;To install &lt;a href="https://byte.ski/notes/TypeScript" rel="noopener noreferrer"&gt;TypeScript&lt;/a&gt; globally on your machine let's use &lt;a href="https://byte.ski/notes/npm" rel="noopener noreferrer"&gt;npm&lt;/a&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;npm install -g typescript
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Alright. Now we need to check that TypeScript was installed. Type this command in the Terminal:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;tsc --version
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;It should print you something like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Version 4.2.4
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;It means that &lt;a href="https://byte.ski/notes/TypeScript" rel="noopener noreferrer"&gt;TypeScript&lt;/a&gt; was successfully installed on our machine. What is &lt;strong&gt;tsc&lt;/strong&gt; command? It is a &lt;strong&gt;TypeScript compiler&lt;/strong&gt;. As mentioned in the &lt;a href="https://byte.ski/blog/article/how-to-install-or-update-node-by-using-nvm" rel="noopener noreferrer"&gt;previous post&lt;/a&gt;, TypeScript compiler is a tool, or program, that turns the TypeScript code into JavaScript code. We need this feature because we will execute this compiled JavaScript code by &lt;a href="https://byte.ski/notes/Node" rel="noopener noreferrer"&gt;Node&lt;/a&gt;.&lt;/p&gt;

&lt;h3&gt;
  
  
  From JavaScript to TypeScript
&lt;/h3&gt;

&lt;p&gt;Alright. To solve the problem we need to write the same code as before but in TypeScript. Let's change extension of the JavaScript file &lt;strong&gt;sum.js&lt;/strong&gt; to TypeScript file extension - &lt;strong&gt;.ts&lt;/strong&gt;. Just rename the file from &lt;strong&gt;sum.js&lt;/strong&gt; to &lt;strong&gt;sum.ts&lt;/strong&gt; and let's see that we will have it in the editor.&lt;/p&gt;

&lt;p&gt;We just renamed our file but there are already some changes in the editor (I use &lt;a href="https://byte.ski/notes/Visual-Studio-Code" rel="noopener noreferrer"&gt;Visual Studio Code&lt;/a&gt;):&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F11b6fgy4ppiedf4ytrfn.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F11b6fgy4ppiedf4ytrfn.png" alt="image" width="600" height="596"&gt;&lt;/a&gt; &lt;/p&gt;

&lt;p&gt;We have several lines with red underlining which means that there are TypeScript errors. There are also two dashed borders on line 11 - TypeScript warnings. But, why don't we just ignore all this stuff and execute our code? Let's try it.&lt;/p&gt;

&lt;p&gt;For executing this file now we must first compile it by TypeScript compiler.&lt;/p&gt;

&lt;p&gt;Run this command in the Terminal to compile TypeScript file &lt;strong&gt;sum.ts&lt;/strong&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;tsc sum.ts
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Oops! After running this command we will see that our code cannot be compiled because of the errors that were marked in the editor.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fwfd0tx9tbd7azwt6cd02.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fwfd0tx9tbd7azwt6cd02.png" alt="image" width="800" height="360"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;And &lt;strong&gt;there is a thing&lt;/strong&gt;. TypeScript won't allow you to compile the code that contains errors. &lt;/p&gt;

&lt;h3&gt;
  
  
  Fixing the code
&lt;/h3&gt;

&lt;p&gt;To compile and execute this file we need to fix the code in the file. Let's see what the errors we have there.&lt;/p&gt;

&lt;p&gt;The first four problems are about the same thing.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;error TS2468: Cannot find global value 'Promise'.

sum.ts:3:18 - error TS2580: Cannot find name 'require'. Do you need to install type definitions for node? Try `npm i --save-dev @types/node`.

3 const readline = require("readline");
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;TypeScript tries to understand the types of modules that we use in the code - &lt;strong&gt;readline&lt;/strong&gt;. To help TypeScript know the types of the modules we need to install &lt;strong&gt;type definitions&lt;/strong&gt;. You will learn about it more in the next posts. For now, let's just say that &lt;strong&gt;type definitions&lt;/strong&gt; is a special notation that helps TypeScript to know types of code that were originally written in JavaScript.&lt;/p&gt;

&lt;p&gt;Let's install it as TypeScript tells us:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;npm install --sade-dev @types/node
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Then, try to compile file &lt;strong&gt;sum.ts&lt;/strong&gt; again:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;tsc sum.ts
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Great! We don't have any errors and successfully compiled our TypeScript file into JavaScript. You should see that there is a new file called &lt;strong&gt;sum.js&lt;/strong&gt; in the same folder as &lt;strong&gt;sum.ts&lt;/strong&gt;. No, this is not the file that we created before. This file contains compiled JavaScript code of &lt;strong&gt;sum.ts&lt;/strong&gt; file.&lt;/p&gt;

&lt;p&gt;If you open this file, well... You may be afraid. There is no our code at all! Don't jump to conclusions. It still the same code as we wrote in &lt;strong&gt;sum.ts&lt;/strong&gt; but it transformed into a form that is more understandable for runtime environment (in our case - &lt;a href="https://byte.ski/notes/Node" rel="noopener noreferrer"&gt;Node&lt;/a&gt;, also it might be &lt;a href="https://byte.ski/notes/Web-browser" rel="noopener noreferrer"&gt;Web browser&lt;/a&gt;).&lt;/p&gt;

&lt;p&gt;Okay, let's execute our code again. But note that we have to execute &lt;em&gt;compiled code&lt;/em&gt;, i.e. &lt;strong&gt;sum.js&lt;/strong&gt;, not &lt;strong&gt;sum.ts&lt;/strong&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;node sum.js
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Let's type new values: 13 and 7. We will see the wrong result, again.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;137
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;But you said that we will solve this problem by using TypeScript and we will catch the errors before executing the file! Well, there is another thing of TypeScript that you need to remember. &lt;em&gt;You wanna help? Help yourself!&lt;/em&gt;. In our case, it means that we have to say to TypeScript where the problem can be.&lt;/p&gt;

&lt;h3&gt;
  
  
  Use types to prevent bug
&lt;/h3&gt;

&lt;p&gt;Let's describe our problem in the code. The function &lt;em&gt;question&lt;/em&gt; returns a value that has a type string. But we don't know about it before executing the file. Because we don't know it we bravely put the values that function &lt;em&gt;question&lt;/em&gt; returns into a parameter of function &lt;strong&gt;sum&lt;/strong&gt;. The function &lt;strong&gt;sum&lt;/strong&gt; expected that values will have type &lt;em&gt;number&lt;/em&gt; and it worked with them as if they were numbers.&lt;/p&gt;

&lt;p&gt;So, firstly, we need to say to TypeScript that function &lt;em&gt;question&lt;/em&gt; returns string type. Let's do it!&lt;/p&gt;

&lt;p&gt;To specify what type of value function returns we should write this code:&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;question&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;message&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt; &lt;span class="kr"&gt;string&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="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Promise&lt;/span&gt;&lt;span class="p"&gt;((&lt;/span&gt;&lt;span class="nx"&gt;resolve&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="nx"&gt;rlInterface&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;question&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;message&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;data&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="nf"&gt;resolve&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;data&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="p"&gt;});&lt;/span&gt;
  &lt;span class="p"&gt;});&lt;/span&gt;
&lt;span class="p"&gt;};&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Hmm. We specified the type of returned value, but TypeScript shows that there is an error:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fwibn83wv1tf9jykp0bjl.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fwibn83wv1tf9jykp0bjl.png" alt="image" width="498" height="171"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;An error sounds like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Type 'Promise&amp;lt;unknown&amp;gt;' is not assignable to type 'string'.ts(2322)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;It means that we cannot just specify the type &lt;strong&gt;string&lt;/strong&gt; as a type of returned value of function &lt;em&gt;question&lt;/em&gt; because the function &lt;em&gt;question&lt;/em&gt; is an asynchronous function and returns Promise.&lt;/p&gt;

&lt;p&gt;Alright. To specify the type in this kind of function we just need to specify it like &lt;code&gt;Promise&amp;lt;your_type&amp;gt;&lt;/code&gt; as TypeScript writes to us in the text of the error.&lt;/p&gt;

&lt;p&gt;Let's fix 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="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;question&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;message&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt; &lt;span class="nb"&gt;Promise&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="kr"&gt;string&lt;/span&gt;&lt;span class="o"&gt;&amp;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="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Promise&lt;/span&gt;&lt;span class="p"&gt;((&lt;/span&gt;&lt;span class="nx"&gt;resolve&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="nx"&gt;rlInterface&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;question&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;message&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;data&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="nf"&gt;resolve&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;data&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="p"&gt;});&lt;/span&gt;
  &lt;span class="p"&gt;});&lt;/span&gt;
&lt;span class="p"&gt;};&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Okay. Did we tell TypeScript there might be a problem? Not yet. The next step is to specify the types of parameters of the function &lt;em&gt;sum&lt;/em&gt;.&lt;/p&gt;

&lt;p&gt;To specify types of function's parameters we should write this code:&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="nf"&gt;sum&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;a&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;span class="nx"&gt;b&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;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;a&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="nx"&gt;b&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;Let's look at the function &lt;em&gt;main&lt;/em&gt; where functions &lt;em&gt;question&lt;/em&gt; and &lt;em&gt;sum&lt;/em&gt; are calling:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fpt6dixrpme3z1i0pq5uo.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fpt6dixrpme3z1i0pq5uo.png" alt="image" width="567" height="338"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;This is it!&lt;/strong&gt;. This is the error that helps us to fix the bug with the wrong result that prints in the Terminal. Now, if we would try to compile file &lt;strong&gt;sum.ts&lt;/strong&gt; we will see the error.&lt;/p&gt;

&lt;p&gt;To run our program in one file use this command:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;tsc sum.ts &amp;amp;&amp;amp; node sum.js
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;We will see:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Frynkniadx2gijorg4ypj.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Frynkniadx2gijorg4ypj.png" alt="image" width="800" height="145"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;All we have to do is to write a code that &lt;em&gt;converts&lt;/em&gt; values from string type to number:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight diff"&gt;&lt;code&gt;&lt;span class="p"&gt;async function main() {
&lt;/span&gt;  try {
    const argX = await question("Type value of X: ");
    const argY = await question("Type value of Y: ");
    + const x = Number(argX);
    + const y = Number(argY);
    - const result = sum(argX, argY);
    + const result = sum(x, y);
&lt;span class="err"&gt;
&lt;/span&gt;    console.log(`Result: ${result}`);
&lt;span class="err"&gt;
&lt;/span&gt;    rlInterface.close();
  } catch (e) {
    console.error(e);
  }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Let's see the result of executing our program:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Flva5qnza41z88kthqu5z.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Flva5qnza41z88kthqu5z.png" alt="image" width="463" height="87"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Congratulations!&lt;/strong&gt; You solve the problem and prevent the bug by using TypeScript!&lt;/p&gt;

&lt;p&gt;TypeScript compiler is a very configurable tool. In the next post of the series we deep dive into configuring TypeScript.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;Do you like the material? Please, &lt;a href="https://byte.ski/newsletter" rel="noopener noreferrer"&gt;subscribe to my email newsletter&lt;/a&gt; to stay up to date.&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://byte.ski/newsletter" rel="noopener noreferrer"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ffld1yqfgvgz2dgcpho0x.png" alt="subscribe" width="545" height="153"&gt;&lt;/a&gt;&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>typescript</category>
    </item>
    <item>
      <title>How To Install or Update Node by Using nvm (Node Version Manager)</title>
      <dc:creator>Max Kovalevsky</dc:creator>
      <pubDate>Sun, 09 May 2021 18:01:20 +0000</pubDate>
      <link>https://dev.to/kovalevsky/how-to-install-or-update-node-by-using-nvm-node-version-manager-1ip1</link>
      <guid>https://dev.to/kovalevsky/how-to-install-or-update-node-by-using-nvm-node-version-manager-1ip1</guid>
      <description>&lt;p&gt;&lt;strong&gt;&lt;em&gt;Subscribe to my email newsletter to stay up to date.&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://byte.ski/newsletter" rel="noopener noreferrer"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ffld1yqfgvgz2dgcpho0x.png" alt="subscribe" width="545" height="153"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Intro
&lt;/h2&gt;

&lt;p&gt;There are few ways to install &lt;a href="https://byte.ski/notes/Node" rel="noopener noreferrer"&gt;Node&lt;/a&gt; on your local machine. The most popular way is to install it following &lt;a href="https://nodejs.org/en" rel="noopener noreferrer"&gt;official website instructions&lt;/a&gt;. But if you use this way you will install just one specific (latest) version of Node. What if you need to install a specific version of Node? Or you need to upgrade from one version to another but only for a short while. &lt;/p&gt;

&lt;p&gt;For that purpose, you can use a tool called &lt;strong&gt;nvm&lt;/strong&gt; (&lt;a href="https://byte.ski/notes/Node-Version-Manager" rel="noopener noreferrer"&gt;Node Version Manager&lt;/a&gt;).&lt;/p&gt;

&lt;h2&gt;
  
  
  Installation
&lt;/h2&gt;

&lt;p&gt;Because I use &lt;strong&gt;macOS&lt;/strong&gt; on my local machine these instructions are specific to that operating system. You can find instructions that are specific to an operating system that you use on &lt;a href="https://github.com/nvm-sh/nvm" rel="noopener noreferrer"&gt;official documentation on GitHub&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;To install &lt;strong&gt;nvm&lt;/strong&gt; on your local machine let's use this command:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.38.0/install.sh | bash
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now let's type the command which tells us that nvm is installed and available on our local machine:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;nvm --version
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You should see the current version of &lt;a href="https://byte.ski/notes/Node-Version-Manager" rel="noopener noreferrer"&gt;Node Version Manager&lt;/a&gt; that is installed on your local machine.&lt;/p&gt;

&lt;h3&gt;
  
  
  Shell Troubleshooting
&lt;/h3&gt;

&lt;p&gt;If you use some shell as &lt;a href="https://byte.ski/notes/Z-shell" rel="noopener noreferrer"&gt;Z shell&lt;/a&gt; or &lt;a href="https://byte.ski/notes/Fish-Shell" rel="noopener noreferrer"&gt;Fish Shell&lt;/a&gt; you probably will have something like this in the Terminal:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;fish: Unknown command: nvm
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Currently, I use &lt;a href="https://byte.ski/notes/Fish-Shell" rel="noopener noreferrer"&gt;Fish Shell&lt;/a&gt;. If you use something else you should check &lt;a href="https://github.com/nvm-sh/nvm#troubleshooting-on-macos" rel="noopener noreferrer"&gt;detail information about troubleshooting on GitHub&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Unfortunately, &lt;strong&gt;nvm doesn't support Fish&lt;/strong&gt;. However, there is a solution called &lt;a href="https://byte.ski/notes/fish-nvm" rel="noopener noreferrer"&gt;fish-nvm&lt;/a&gt;. It is a wrapper for &lt;a href="https://byte.ski/notes/Fish-Shell" rel="noopener noreferrer"&gt;Fish Shell&lt;/a&gt;. You can install this by using &lt;a href="https://byte.ski/notes/Fisher-(Fish-Shell-Plugin-Manager)" rel="noopener noreferrer"&gt;Fisher (Fish Shell Plugin Manager)&lt;/a&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;fisher install FabioAntunes/fish-nvm edc/bass
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now, if you type &lt;code&gt;nvm --version&lt;/code&gt; you should see a version of &lt;a href="https://byte.ski/notes/Node-Version-Manager" rel="noopener noreferrer"&gt;Node Version Manager&lt;/a&gt; that is installed on your local machine.&lt;/p&gt;

&lt;h2&gt;
  
  
  Usage
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Node Installation
&lt;/h3&gt;

&lt;p&gt;Now it's time to start using &lt;a href="https://byte.ski/notes/Node-Version-Manager" rel="noopener noreferrer"&gt;Node Version Manager&lt;/a&gt; to install &lt;a href="https://byte.ski/notes/Node" rel="noopener noreferrer"&gt;Node&lt;/a&gt; on the local machine.&lt;/p&gt;

&lt;p&gt;To install &lt;strong&gt;latest&lt;/strong&gt; version of Node you can use the command:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;nvm install node
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;To see all versions of Node that are installed on your machine use the command:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;nvm ls
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;It should print in the Terminal something like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;-&amp;gt;      v16.1.0
         system
default -&amp;gt; node (-&amp;gt; v16.1.0)
iojs -&amp;gt; N/A (default)
unstable -&amp;gt; N/A (default)
node -&amp;gt; stable (-&amp;gt; v16.1.0) (default)
stable -&amp;gt; 16.1 (-&amp;gt; v16.1.0) (default)

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

&lt;/div&gt;



&lt;p&gt;Pay attention to the symbol "-&amp;gt;". It shows us which version of Node is current on the local machine. So, basically, when you type &lt;code&gt;node -v&lt;/code&gt; you should see the same version as with "-&amp;gt;" before (in that case this version is 16.1.0).&lt;/p&gt;

&lt;p&gt;Now let's install another version of &lt;a href="https://byte.ski/notes/Node" rel="noopener noreferrer"&gt;Node&lt;/a&gt;. Let's say, I want to use some older version of Node. For example, 14 version. To install it use the command:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;nvm install 14
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;It should install Node v.14.16.1. Let's look at the list of installed Node versions (&lt;strong&gt;&lt;em&gt;nvm ls&lt;/em&gt;&lt;/strong&gt;):&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;-&amp;gt;     v14.16.1
        v16.1.0
         system
default -&amp;gt; node (-&amp;gt; v16.1.0)
iojs -&amp;gt; N/A (default)
unstable -&amp;gt; N/A (default)
node -&amp;gt; stable (-&amp;gt; v16.1.0) (default)
stable -&amp;gt; 16.1 (-&amp;gt; v16.1.0) (default)

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

&lt;/div&gt;



&lt;p&gt;Now we have two versions: 14.16.1 and 16.1.0. The current is 14 (the symbol "-&amp;gt;" before).&lt;/p&gt;

&lt;p&gt;To &lt;strong&gt;switch to&lt;/strong&gt; version 16 use this command:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;nvm use 16
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;We should see the answer of nvm:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Now using node v16.1.0 (npm v7.11.2)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;And if we use the command &lt;strong&gt;&lt;em&gt;nvm ls&lt;/em&gt;&lt;/strong&gt; again we will see that the current version is 16.1.0.&lt;/p&gt;

&lt;h3&gt;
  
  
  Uninstall Node
&lt;/h3&gt;

&lt;p&gt;To uninstall &lt;strong&gt;latest&lt;/strong&gt; version of &lt;a href="https://byte.ski/notes/Node" rel="noopener noreferrer"&gt;Node&lt;/a&gt; use command:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;nvm uninstall node
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;To uninstall &lt;strong&gt;specific&lt;/strong&gt; version of Node (for example - 14) use command:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;nvm uninstall 14
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Global npm packages
&lt;/h2&gt;

&lt;p&gt;If you have some installed globally &lt;a href="https://byte.ski/notes/npm" rel="noopener noreferrer"&gt;npm&lt;/a&gt; packages you should notice one thing. When you installed this npm package on one version of &lt;a href="https://byte.ski/notes/Node" rel="noopener noreferrer"&gt;Node&lt;/a&gt; and then you switch to another version of Node, the installed npm package won't be available for you. It's because npm packages that were installed on different versions of Node located in different places.&lt;/p&gt;

&lt;p&gt;An example. Now I am on version 16 of &lt;a href="https://byte.ski/notes/Node" rel="noopener noreferrer"&gt;Node&lt;/a&gt;. I want to install &lt;a href="https://byte.ski/notes/Prettier" rel="noopener noreferrer"&gt;Prettier&lt;/a&gt; globally on my computer by &lt;a href="https://byte.ski/notes/npm" rel="noopener noreferrer"&gt;npm&lt;/a&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;npm i -g prettier
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;And then we switch to version 14:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;nvm use 14
prettier --version
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You will see something like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;prettier: command not found
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Don't worry! If you want to use that package on version 14 you just need to install it again.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://byte.ski/notes/npm" rel="noopener noreferrer"&gt;npm&lt;/a&gt; packages are located in specific folders for each version of &lt;a href="https://byte.ski/notes/Node" rel="noopener noreferrer"&gt;Node&lt;/a&gt; that is installed by &lt;strong&gt;nvm&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;Packages are located here (on macOS):&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;~/.nvm/versions/node/&amp;lt;version&amp;gt;/lib/node_modules
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;&lt;em&gt;Do you like the material? Please, &lt;a href="https://byte.ski/newsletter" rel="noopener noreferrer"&gt;subscribe to my email newsletter&lt;/a&gt; to stay up to date.&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://byte.ski/newsletter" rel="noopener noreferrer"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ffld1yqfgvgz2dgcpho0x.png" alt="subscribe" width="545" height="153"&gt;&lt;/a&gt;&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>node</category>
    </item>
  </channel>
</rss>
