What is typscript, and what is it used for?

What is typscript, and what is it used for

TypeScript is a programming language that can be an alternative to JavaScript. It's actually known as a superset of the JavaScript language, meaning that it basically extends the language with new features and syntax, so it can do all of the same things that JavaScript can do, but it also comes with extra features and new syntax.

In this article, we will learn what TypeScript is, what its uses are, why we use it with React, what the basics are for using it with React, and what the difference is between dryscript and typescript.

So what does typescript mean?

typescript is a superset of javascript, but it's not like it is adding more features to javascript; it doesn't give you more of a callback; it doesn't give you more of an arrow function; it just allows you to write javascript in a much more precise manner.

Typescript is not about reinventing the entire JavaScript language; it is just asking that you write JavaScript with a little bit more accurate behavior. Don't just do anything; just try to write your JavaScript in a more precise manner.

Using TypeScript

Using TypeScript

Browsers by default do not understand typescript like they do JavaScript, so when we write typescript, we then have to compile it down into JavaScript in order for browsers to understand it. Now, do not let that extra step put you off using typescript because, in most cases, it's very easy to compile it down, and typescript comes with a load of useful features, and the first of those features is that it.

  • allows us to use strict types No, that means that if I declare a variable in typscript to be a certainr type, like a number, I then can't change that type later, running that variable to a string, a boolean, or something else.
  • All of the error-checking and debugging of our code becomes a little bit easier.
  • It also forces us to write cleaner and better code that is less error-prone to begin with.
  • We can also use modern features seen in later versions of JavaScript that might not yet be fully supported directly in browsers. These could be things like error functions, const destructuring, etc.
  • includes extra features that don't appear in Javascript, like generic interface tuples and more.

All of those features that are not automatically supported in every single browser, we can use in typescript, and because that's then compiled down into javascript, it's older javascript, which the browsers do understand okay, so it's similar to something like the Babel compiler, which allows you to use modern javascript features.

You Must Learn Typescript

You might be wondering if it makes sense to invest your time in learning TypeScript for front-end development. Yes, it makes a lot of sense, but only if you already master JavaScript.

Why is typescript so important? First of all, it is extremely popular in companies nowadays because it brings safety to your javascript, even with small functions.

Get the full name with our name andame, where we type the stram and the return parameter string. We're 100% sure that we can't call this function. Without parameters, with one parameter, or with other data types, you are sure that this function will be called only with the correct parameters. Because of this safety, companies invest in typescript.

Javascript vs. Typescript for beginners

  • Typescript is object-oriented programming, while JavaScript is a prototype-based language.
  • Typescript has a feature known as static typing, whereas JavaScript does not support this feature. TypeScript takes more compilation time as compared to JavaScript.
  • TypeScript is not specific to a single environment; you can run it on any browser.
  • All the JavaScript code can be converted into typescript for more such insightful content.

You must know before learning TypeScript.

Before you start learning TypeScript, I expect you already understand things


  •  Arrow functions.
  •  The Dom.
  •  Classes.
top 5 typescript courses on udemy in 2024

why typescript & React?

why typescript & React?

  • safely that it has improved the overall development experience for you. With static type checking, you get to learn about potential bugs as and when I'm typing the code, rather than heading to the browser and figuring it out at runtime. 
  • It also provides a way to describe the shape of an object, thereby providing better documentation and autocomplete.
  • TypeScript even makes maintenance and refactoring of large code bases much easier. As you can see, there are some pretty good points to help you make the decision to adopt TypeScript in your code.
  • Typescript is just frustrating most of the time.you have to write a lot more code than I normally do, and the compiler keeps complaining. you simply don't know what to do about those errors.

React and Tyescript Basics

Here are the most important things you have to know if you want to start using React with TypeScript.

  1. All props that you pass to a component have to be typed when you use typescript.
  2. for this. Create an interface that contains all props together with their types. Then pass these props to your component and destructure them with curly braces so you can access each individual prop directly.
  3. If a prop is not required, you can make it optional by adding a question mark before the variable name.
  4. If you use useState in your component, then you can declare the type between angle brackets. This is only necessary if the
  5. type can't be the default value; for example, when you pass null to useState, passing the type to createContext works the same.
  6. If you want to accept null or undefined as the default value, you can add this type with a vertical bar input. The input field submit function can accept a form event of type HTML form element, and out of this, you can get the current value of the input fields.


Typescript is an open-source language by Microsoft that is a strict version of JavaScript. By adding types, when you run Javascript code, errors are not caught at runtime, so they happen by surprise. With typescript, you add more boilerplate code, but because of this, you can catch your errors before launching your app instead of getting an angry email about them. Because of this, typescript is loved by developers, so if you aren't using it, you are missing out. Typescript can be easily added to your project even if you don't have TS files. What are you waiting for?

Post a Comment

Previous Post Next Post

نموذج الاتصال