5 USES OF TYPESCRIPT That You Don’t Know

💡 TypeScript is used to more than develop websites in React, Vue or Angular.

These are the 5 uses of TypeScript that you didn’t know about.

Categories
Web Development

What is TypeScript for?

Are you considering learning TypeScript or do you already use it to develop web pages? If you find yourself in either of these 2 situations, it will be interesting for you to know some of the most important use cases of this versatile programming language that is used for much more than building website clients.

YouTube player
This video is in Spanish, but you can activate the English subtitles.

TypeScript, the superset that adds static typing to JavaScript, currently boasts one of the largest communities in the industry. I’d even dare to say it’s the most widely used programming language worldwide.

The primary driver behind TypeScript’s widespread adoption is undoubtedly frontend web development in React, Angular, Vue, and many other frameworks. However, the countless code libraries available for this language, which provide functionalities and enable integration with other systems, have turned it into a programming language suitable for nearly any task.

I’m Carlos Sala, a software developer, and this time I’m bringing you 5 lesser-known use cases of TypeScript to persuade you, if you’re not already convinced, that learning TypeScript is essential.

#1 – Backend Web Development with TypeScript

What would you think if I told you that you can be a fullstack developer using a single programming language?

Frodo from The Lord of the Rings with the ring.

In addition to frontend development, you can also program web servers using TypeScript. This makes it one of the best candidates as a first language for starting programming since you can learn TypeScript, explore both frontend and backend simultaneously, and develop complete web pages without closing any doors. Just in case you decide to specialize in either client-side or server-side development in the future.

Node.js Frameworks in TypeScript

When developing a web server in TypeScript, there are numerous frameworks available on Node.js with varying features to select from. Some of the most recognized ones include Express.js, NestJS or LoopBack. These frameworks enable us to establish HTTP routes for building a REST API or a microservice.

Manage the Database with TypeScript

And the connection to the database?

So, you might think you need to dive into learning a query language like SQL, correct?

But hey, consider this: TypeScript could step in here too! With an ORM, we can sidestep the need for writing SQL queries, especially when working with relational databases.

Alternatively, we could opt for a non-relational database like MongoDB, which we can seamlessly interact with directly in TypeScript.

Fullstack Development in TypeScript

As you can see, if we recycle the knowledge we have, we could build a website from the client to the server using only TypeScript.

Tank representing TypeScript as a general-purpose programming language.

This stands as one of the reasons making this programming language immensely appealing to businesses. It empowers them to scout for fresh talent effortlessly and enables flexible role rotations within the company, eliminating the need for mastering additional programming languages.

For freelancers in the field, the perks are quite evident too. It’s far simpler to write and recycle code when consistently using the same programming language, rather than juggling between different ones for client and server tasks.

#2 – Mobile Applications Development with TypeScript

And what about mobile applications?

Is there a way to write TypeScript code that can later be distributed, installed, and run on Android and iOS?

Well, luckily, yes! There are primarily two approaches we can take to achieve this.

Hybrid App Development with TypeScript

The first, and easiest to grasp if you come from web development, is to build hybrid applications. In essence, a hybrid application is a web application that we can install on our mobile or tablet written in HTML, CSS, and TypeScript, with a user interface design well-suited for mobile screens.

3 characters building a mobile application with blocks.

Every time we open the hybrid application on our device, a lightweight web browser seamlessly runs the project, giving the impression of a native application. However, in reality, we encounter the same limitations as in any web development while coding.

To package our web application as if it were native, we need to use a solution like Capacitor or Cordova. These technologies also allow us to access native device functionalities through installable plugins. But I won’t sugarcoat it, every time I try to implement native behavior like displaying an animated splash screen in hybrid applications, I run into a million problems or glitches before achieving something close to what I intended.

So personally, hybrid applications don’t convince me, but it’s true that it might be the simplest option if your background is web development.

Mobile Applications Development with React Native

And the second option for developing mobile applications in TypeScript is to use Expo and React Native, which, in my opinion, is the best technology available today for developing Android and iOS applications with a single source code.

Screenshot of the home page of React Native.

Some people prefer Flutter or Xamarin, and I respect that, but React Native seems more appealing to me. Especially because it allows development in TypeScript, which is well-known among programmers today.

With React Native, you write your code once in TypeScript, almost identically to React, and it’s instantly available on all platforms. What’s more, the resulting code is native code for Android and iOS, resulting in smoother interfaces than what you can achieve with hybrid applications in HTML.

As for executing native APIs in React Native, it’s possible to access them through libraries, and if needed, we can also craft our own modules in Java, Swift, or C++ to create custom functionalities.

#3 – Command Line Interfaces (CLI) in TypeScript

Have you ever tried building a command-line interface or CLI?

Options menu of the Vue CLI in TypeScript.

Not everyone is aware, but TypeScript shines when it comes to developing terminal applications. Tools like Commander.js streamline the development of CLIs of any complexity, which we can ultimately run using the Node command on our machine.

node ./examples/pizza

Command-line interfaces are handy for distributing a set of functionalities without needing to develop a graphical interface for user interaction. However, it’s worth noting that the majority of non-programmers aren’t familiar with how to use them. Therefore, they’re primarily intended for software developers, experienced users, or for task automation.

Passing parameters to scripts or displaying the manual of your terminal application are some of the possibilities offered by these CLI development libraries. Explore the documentation of packages like Commander.js to make the most out of your command-line interface in TypeScript.

If you’ve ever wondered what technologies power the console tools you use for software development, now you know that one of the options is they’re written in TypeScript.

#4 – Artificial Intelligence Development with TypeScript

While it’s true that when we talk about artificial intelligence, the first programming language that comes to mind is Python, nowadays it’s also possible to develop applications utilizing artificial intelligence in TypeScript.

Two humanoid robots representing the artificial intelligence concept.

The main reason why people use TypeScript in artificial intelligence development is because they come from web development backgrounds, avoiding the need to start from scratch with Python before being able to try a library like, for instance, TensorFlow.

TensorFlow: Google’s Artificial Intelligence Library

TensorFlow is one of the most well-known artificial intelligence libraries in the world of software development. This library enables you to easily create machine learning models and boasts excellent documentation and a large community, making it very straightforward to learn how to use.

In its JavaScript version, TensorFlow can be executed both in a web browser and in a Node.js process, depending on the environment we’re in. This makes it a perfect candidate for portable artificial intelligence systems that can run on practically any computer with a web browser.

<script src="https://cdn.jsdelivr.net/npm/@tensorflow/tfjs@latest/dist/tf.min.js"></script>
npm install @tensorflow/tfjs

The possibilities for applications we can build with machine learning models are endless: from a lip-syncing system to a system for controlling video games with your movements in the real world.

If you want to start using TensorFlow in TypeScript, I recommend visiting its official website where you’ll find numerous examples illustrating its API documentation.

#5 – Game Development with TypeScript

Did you know that you can also develop video games in TypeScript without having to learn another programming language?

Timmy Turner from The Fairly Oddparents playing videogames.

After all, a video game is nothing more than an infinite loop, called the Game Loop, which iterates every few milliseconds, depending on the FPS configuration we have set, and refreshes the views on the screen with the updates that have occurred in the data layer.

Browser Games and WebGL

Games written in TypeScript run in a web browser and utilize the HTML5 canvas element as a canvas to display graphics on a Cartesian coordinate system. The canvas, in turn, makes use of the WebGL API to build high-performance interactive applications with 2D and 3D graphics. Currently, all modern browsers support this web version of OpenGL.

Moreover, we don’t need to build our games from scratch, with all the work that entails. Just like on other platforms where game engines like Unity or Unreal Engine exist to make easier development, in TypeScript, we have different engines to streamline the programming of browser games.

Game Engines in TypeScript

There are many others, but I believe Phaser for 2D or Babylon.js for 3D are the most mature engines for developing native browser games and integrating them into a complete web application. So, I recommend choosing one of them as a starting point for your game to leverage all the issues that have already been solved by their communities and avoid getting stuck at any point.

Phaser logo and some of the most important features of the videogames engine.

For those coming from web development, I’m sure you’re excited to discover that you can also make games with what you already know. I encourage you to try out one of these engines to take your first steps as game developer.

Personally, I started with browser game development. This helped me understand how game engines work internally and learn basic techniques used in game development.

What Experience do You Have with TypeScript?

Have you already tried to use TypeScript to develop other than web frontend project?

Character with interrogative face.

Can you think of any interesting use case for this language that I may have forgotten to mention or another language that you consider more versatile than TypeScript?

Don’t forget to follow me on social media if you enjoyed this article and want me to continue publishing content like this regularly.

Once again: I’m Carlos Sala, software developer and see you soon!

Carlos Sala Samper

Handmade software.