DEV Community

Cover image for My struggles with TypeScript
alexpaper
alexpaper

Posted on

 

My struggles with TypeScript

Premise

TypeScript has changed the schemes, the first time I heard about it, I thought πŸ€”:

"Simple, just declare the data type and that's it"!

I soon realized it's not that simple! 😞

Things are not exactly like this and in any case, this logic applies to everything, variables, objects, functions, classes, etc., in short, it is another way of programming, it is another way of thinking, you have to completely change your approach!

Realization

The best ones can do amazing things with TypeScript, I think it has now become an essential tool for those who regularly use JavaScript!

I have developed some little projects in React, some simple applications, a blog, and I must admit that the idea of redoing everything with TypeScript scares me deeply! 😱

The secret to learning is to practice constantly! So, since I am constantly looking for work, I made this little application using JavaScript and TypeScript to see the newest job offers on the market!

Some examples.

For example, if you use axios package, in normal project, you simple need to import the package, in TypeScript you need also to import AxiosResponse to specify the type of the axios response, like this:

// Import axios
import axios, { AxiosResponse } from 'axios';

Enter fullscreen mode Exit fullscreen mode

If you have an object, you need to describe the shape of it using β€˜Interfaces’;

interface Job {
title: string;
description: string;
company: {
display_name: string;
};
location: {
display_name: string;
};
category: {
label: string;
};
contract_type: string;
created: string;
latitude: number;
longitude: number;
redirect_url: string;
salary_min: number;
salary_max: number;
}

Enter fullscreen mode Exit fullscreen mode

Sure, the code becomes more robust, but it is easy to understand that in this way the code extends beyond measure, to be clear, it is not a criticism, but an simple observation!

Conclusions.

Slowly using TypeScript I have to admit that I start to like it and as I said before, I think it has become an essential tool, in fact I see it in job requests, before employers only asked for JavaScript, now they also ask for TypeScript!

In this video you can see my struggles with TypeScript.

Have a Good day! πŸ‘‹

Top comments (1)

Collapse
 
andrewbaisden profile image
Andrew Baisden

TypeScript does have a learning code and maybe you will be writing more code but it's worth it for the improvements that it brings.

Visualizing Promises and Async/Await 🀯

async await

Learn the ins and outs of Promises and Async/Await!