Typescript for beginners: Setting up a new project using ReactJs
Tags: typescript, react, javascript, webdev
Published: 2023-02-06 08:43:31

As a developer, you will almost certainly have to work with Javascript at some point in your career, regardless of whether you're a front-end or back-end engineer. Sometimes it can be tiring to work with Javascript due to runtime errors when it comes to type checking, which is why Typescript, a superset of Javascript that extends Javascript, was introduced. 

It allows for type checking before runtime, improves the productivity of developing complex applications, and reduces type errors drastically before production.

In this article, as a beginner familiar with React JS, you will learn how to create your first typescript project using the Visual Studio code editor or any other editor you choose.

## Prerequisites 
- Vscode editor Installed (or any other preferable editor).
- Node installed on your device.
- Basic understanding of ReactJs.


## Why I chose Typescript

"Hi Aisha, we will be using Typescript in our next project."

This was the message I received from my colleague recently. Let me introduce myself. My name is Aisha, and I am a front-end developer who uses JavaScript and is now going to work with Typescript. Who am I to say no when it involves learning new things? 

Before my colleague informed me of it, I had already heard about Typescript on the internet, but I never gave it a shot or a second glance. Some developers believe it is superior to Javascript, while others believe vice-versa. However, I conducted my research, but first, let us define Typescript.

## What is Typescript?

Typescript, according to its official documentation page, is a superset of Javascript. According to our high school mathematics knowledge of SETS, set A is a superset if it contains all of the elements of set B. Relating this to the definition of Typescript above, this means that Typescript contains all elements of Javascript.

However, Typescript is a statically typed language compared to Javascript, meaning you must explicitly indicate its value type. It is a more readable version of Javascript thanks to type-checking and intuitive compilation. Typescript adds syntax rules about how to use different values, which aid in type error checking before execution.

## Setting up a new Typescript project using react

If you've used reactJs libraries to build Javascript projects in the past, you might wonder if there's a different way to build Typescript projects with the same library. No need to worry because in this section, you will learn how to create a Typescript from scratch using the React library.

### Steps to set up a Typescript project


1. Open your editor and navigate to the terminal.
![Vscode Terminal](https://lh5.googleusercontent.com/Iaeilz2E6EFuLilNINeBoRl1MbLLWoCKXoadqBMH7y0-emhe82SJx05fE9kx3NodU1O2eYABt9AgjujMYlMAa3GtbR6S3MpBggr2miWD_tsNL90nLSi4nv_o65g1NmsObldXYP6XMRLsOmFidviI2p2gFQRWcyPtJiNjc2mdhKdKsZZJl4WuYL24EhVO7A)

2. Cd into the desktop and make a new directory on the desktop and name it Typescript-project-tutorial.
![Vscode Terminal](https://lh5.googleusercontent.com/DKqku7_QcBkrkFL1I0wVpDA0-lEDwOyaRA6UVHWMbrvnuS1iEp1vnXxStuQiszvU6jOTkBwe_oarvB1jYUBS2klNylHKSCnMtsYZYo_CJnMFbJIB_qy8tMVUg4SFyOUEifwCdRChKi5zdAYBZ09qmPyosL0GJb8cYfgSyyAAPjaoqwbQjvNDIQc76Rjj1Q)

3. Cd into the new directory created on the desktop.
![Vscode Terminal](https://lh4.googleusercontent.com/MhPTpdb_pwzEeOkpnerTjkzX8LNcOygphOcCeP3RwWFuixZ18cGFxpZ2Wdtb9zYq0yvufE7QjRPBWftVs6bxKLv8ozlJ6iaTJYIGyDJozT0XUv_9YD5pDzjIAxD_pwk3ubmy9SIyrJQc3xJQSVAFo3RkCDgvA6kGU1DMWsY3iFx-KjfEVTbnFZ23oRj5-w)

4. Create a new Typescript project using react by adding `--template typescript`.
![Vscode terminal](https://lh4.googleusercontent.com/y4bITr0OOXSvkEzhks0RUJlvplvacVpuntyGl491xUOTgrpXPLr-zK4sRefOLu7L8XeSBJRLC8Nqt7byE80qOMBtfaHz6xr9V8vfh5OzioQ0wLNeTABIEeVaaM5i_ZAxYfpgfxIAwKYqA_17xwF9yEibqz1QB7_dQm4rGoZuh0J23gzl_g-HRZEqLctWsg)

5. After Installation, you get the folder structure below, including a Typescript config file.
![Typescript project folder structure](https://lh5.googleusercontent.com/v_m45VD5J1p4my474l4I2p21EAwM_VYqXRHH9uQERysDrhisza64YWSh5PhUAWjieR4ViD4Cvj2cHvzTCDf9xzaB8DKdY96NOc9qHHBLrgMhkyIAorfoPMczniNgki9z3CDAdL24J18DNzCJgVWqCCW98lmPSGdoVKBLCIkUglCUKOhT9EXureKq_LEggA)


Now that you've successfully started a Typescript project with the Reactjs library, you can remove unnecessary files and rearrange your project directories anyhow you want it.

## Conclusion

In this article, you learned what Typescript is and how to create a Typescript project using the ReactJs library. For further understanding of Typescript, you can check out the following resources.


## Resources
- [Typescript documentation page.](https://www.typescriptlang.org/docs/) 
- [React Typescript documentation page.](https://www.typescriptlang.org/docs/handbook/react.html) 

Thank you for sticking with me this far. You can connect with me on [Twitter](https://twitter.com/fav_watchgirl) | [Github](https://github.com/Aysha-py)| and [LinkedIn](https://www.linkedin.com/in/aishat-muhammed/)
See you in my next article! cheers.