How to install TypeScript on Linux (AlmaLinux)

Reading Time: 5 minutes

TypeScript is a typed superset of JavaScript that improves regular JavaScript with classes, interfaces, and optional static typing. Using TypeScript can improve developer efficiency and code quality for complex JavaScript applications. Regarding the TypeScript compiler, it can be launched with the tsc command, translating the TypeScript file into vanilla JavaScript. A ts configuration file is a project artifact required for TypeScript, allowing us to modify the compiler's behavior.

TypeScript is entirely object-oriented, like Java, and has classes, objects, and interfaces. Before, we were not required to specify the data type of JavaScript variables and objects, which made the logic more challenging to understand overall because we didn't know what kind of data we were working with. This issue is resolved by TypeScript, which gives developers a mechanism to specify the data types for variables and objects.

Key points

Before delving into how to install TypeScript on AlmaLinux, let's take inventory of its advantages and disadvantages. In addition to those, there are some main points you will walk away with after reading this article:

  • Knowing the advantages of TypeScript.
  • Understanding the disadvantages of TypeScript.
  • Having the prerequisites to consider before learning how to install TypeScript.
  • Possessing the steps to install TypeScript on AlmaLinux.
  • Updating TypeScript.
  • Uninstalling TypeScript.

Advantages of TypeScript

Incorporating TypeScript into a web application development project has a number of benefits. These benefits are described in detail in the following subsections.

Maintainability of code

TypeScript implements a more systematic approach to coding. Explicit type annotations enable code to become self-documenting, which helps with comprehension and maintenance for developers. In addition, TypeScript encourages developers to think about interfaces before patterns, which is a wise approach. Our company's experience has shown that TypeScript is best leveraged for high-quality web development efforts.

Improved coordination

TypeScript allows better developer communication when a project involves multiple software engineers. Code is now easier to understand, especially for team members unfamiliar with a particular area of the codebase, thanks to the additional type annotations. In particular, it improves quality and shortens the duration of code reviews, an essential step in developing every project. Additionally, it facilitates and expedites the onboarding process for a new developer working on a project.

Fewer issues

Static type checking in TypeScript aids in the early detection of any mistakes and faults. Type-conflict bugs are reduced to nearly zero, and several other bugs are greatly reduced as well. An improved user experience and less time spent on issue fixes are the outcomes of this proactive approach to bug discovery, which produces more stable and dependable apps.

Community of developers and ecosystem

TypeScript has active user community and a large set of libraries and frameworks created especially it. Developers can access a multitude of tools and resources, such as type definitions for pre-existing JavaScript libraries, by utilizing TypeScript. TypeScript compatibility is provided with an extra package, including types found in the most widely used JavaScript libraries. In addition, some libraries and frameworks were created specifically for TypeScript. Take Google's Angular, for instance, as similar example regarding its community and ecosystem for developers.

Disadvantages of TypeScript

Although there are many benefits of using TypeScript, it is true that there may also be some drawbacks. Let's review them here.

Additional coding

Because TypeScript adds static typing, developers now have to create type annotations. While working on smaller projects or in the early stages of development, TypeScript can add to the development time. It's crucial to remember, though, that TypeScript contributes to shorter development times down the road for the previously mentioned reasons.

Cases of complexity

TypeScript can be difficult at times, especially when working with complicated scenarios or when it's unclear which types are correct. In these situations, developers could decide to disregard type declarations in order to fulfill deadlines or because they are having trouble determining the right typing solution. But if essential types are omitted, TypeScript's advantages may be diminished, raising doubts about the practicality of its use.

Incorporating optional technology

TypeScript is a programming language that developers must understand in order to work efficiently on a project that uses it. Nevertheless, since TypeScript is really a superset of JavaScript, developers of JavaScript may easily accomplish it.

Prerequisites to consider before learning how to install TypeScript

Here is a list of the prerequisites for an install of TypeScript using this article:

Steps to install TypeScript on Linux (AlmaLinux)

We'll walk you through how to install TypeScript on Linux — specifically AlmaLinux — in this article.

Step #1. Update the AlmaLinux system

Install the most recent versions of the system packages. By performing this step, you can be sure you have the most recent security updates and system enhancements. To get started, the command to clean up your system is as follows:

sudo dnf clean all

Then, command to update your system is:

sudo dnf update

Step #2. Install Node.js on the server

The AlmaLinux basic repository has Node.js. Use the following command to install Node.js:

sudo dnf install nodejs

Then, check if Node.js and NPM (Node Package Manager) have been installed successfully.

Run the command below:

node --version

And, then the following command:

npm --version

The output will look somewhat as shown below:

# node --version

v10.24.0

# npm --version

6.14.11

Step #3. Install TypeScript

TypeScript installation requires the usage of NPM, also known as Node Package Manager. As its name implies, it is used to install Node.js packages on our system. NPM is included with Node.js and must not be installed separately. See our How to install Node.js on Linux (AlmaLinux) article for more details.

You may use TypeScript over your system by installing it globally (the -g in the command below represents globally):

npm install -g typescript

Check TypeScript's version after installation to ensure it was installed correctly:

tsc --version

The TypeScript version that is installed should be shown by this command.

Use the command typescript@ followed by the version of TypeScript to install a specific version. For example, you can run the command as shown below:

npm install --global typescript@5.3.3

Step #4. Configure TypeScript

It is necessary to build a tsconfig.json file after installing TypeScript. To ensure that your TypeScript project gets compiled, you can use this file to provide the root files and compiler settings.

Execute the following command to produce a basic tsconfig.json file:

tsc --init

Step #5. Test TypeScript

After installing and configuring TypeScript, create a basic TypeScript file main.ts, to test it.

And then, add the following script in it:

let message: string = "Hello Typescript";
console.log({message});

Step #6. Compile with tsc

Next, compile with tsc by running the following command:

tsc main.ts

This command above generates a JavaScript file called main.js that you can run using Node as per the command shown below:

node main.js

TypeScript should print "Hello Typescript" verifying that it works correctly. Congratulation on learning how to install TypeScript! Read on for a few more helpful guidelines for related tasks.

How to update TypeScript

After understanding better how to install TypeScript, you may have a future scenario where TypeScript requires updating.

Step #1. Update TypeScript

You can update the TypeScript version on AlmaLinux by simply running this command:

npm -g upgrade typescript

Or by running the command below:

npm install -g typescript@latest

The -g portion of the command syntax means global installation mode.

Step #2. Check the version of TypeScript

Next, check the version by running the below command:

tsc -v

How to uninstall or remove the TypeScript

The primary focus of this article has been how to install TypeScript. However, should you need to remove TypeScript from the system, here are the steps involved in the following sections:

Step #1. Uninstall TypeScript

The user can use the following "uninstallation" command to remove TypeScript:

npm uninstall -g typescript

The -g portion of the command syntax means global mode.

Step #2. Examine the removed package confirmation message

The example output is as shown below:

# npm uninstall -g typescript
removed 1 package in 0.171s

The TypeScript package will thereafter be permanently deleted from the system.

Wrapping up this tutorial on how to install TypeScript

This article teaches you everything you need to know about TypeScript. Along with its advantages and disadvantages, learn how to install TypeScript on AlmaLinux. Create a basic TypeScript file and compile it into JavaScript code. Update and uninstall TypeScript easily with our instructions above.

With a quality hosting provider, your online presence can impress your site visitors, including potential customers of the products and services you sell via ecommerce. Let Liquid Web help you deliver a stellar website with all the technology you need built into it for providing an excellent user experience.

Avatar for Amritha Varshini

About the Author: Amritha Varshini

With a Bachelor of Engineering in Information Science, Amritha Varshini has been working as a Linux Admin for Liquid Web since 2018. Varshini has worked on multiple operating systems, such as CentOS, AlmaLinux, and Ubuntu and on servers, like VPS, cloud, shared, reseller, and dedicated.

Latest Articles

Change cPanel password from WebHost Manager (WHM)

Read Article

Change cPanel password from WebHost Manager (WHM)

Read Article

Change cPanel password from WebHost Manager (WHM)

Read Article

Change cPanel password from WebHost Manager (WHM)

Read Article

Change the root password in WebHost Manager (WHM)

Read Article