Sitemap

A Quick Look into Typescript

3 min readDec 9, 2022

--

What is a type script? Today we are going to talk about what typescript is and why it is typescript

Press enter or click to view image in full size

TypeScript is a language by Microsoft built on top of JavaScript. Unlike JavaScript, it’s a strongly typed language.
It has all the features and functionalities of JavaScript, which makes it a superset of JavaScript.

Press enter or click to view image in full size

Why TypeScript?
TypeScript provides static typing and improves the developer experience by pointing out compilation errors during development. This makes runtime errors less likely.
JavaScript is a dynamic language and type conversion may cause some expected results and behaviors. TypeScript helps us to avoid those unexpected behaviors.

//CODE. User is a string, it can’t be converted to an integer
let user = “Tassu”;
user = 99; // Returns error

Press enter or click to view image in full size

The Syntax.
TypeScript’s syntax is the same as JavaScript’s. Here’s an example of how to create an object in TypeScript.

//CODE
const user = {
firstName: “Tassu”, LastName: “Ali”, role: “MERN Stack”,
}
console.log(user.name) // Return error
// Name doesn’t exist in the user object

Press enter or click to view image in full size

Initiate a Project
To initiate a TypeScript project, unlike React.js, we don’t need to set up many things.
All we need is to install TypeScript’s npm package.

//CODE
npm install -g typescript

Next, we create a file with a .ts extension in a folder.

//CODE
function greeter (person: string) {
}
return “Hello,” + person;
let user “Tassu User”;
console.log(user);

Press enter or click to view image in full size

Compile TypeScript
TypeScript is a language built on top of JavaScript, but browsers don’t understand it, which is why the TypeScript code has to be converted to JavaScript. We can do so by using the following command.

//CODE
tsc index.ts

This will create a Javascript version of the code.

Press enter or click to view image in full size

What’s Next?
That’s the very basics of TypeScript. We have many resources available on the internet to learn more.
One of the most helpful places to start is the TypeScript docs itself.
https://www.typescriptlang.org/docs/

Press enter or click to view image in full size

If you need any help or guidance about the coding/programming life just ping me on Instagram at https://www.instagram.com/codeculturepro/ or on Gmail at codeculturepro@gmail.com

--

--

Tasadduq Ali
Tasadduq Ali

Written by Tasadduq Ali

I am MERN Stack developer working in UAE Govt to digitize their massive services. I will help you to become highly skilled Coder 😉