How did you switch from JavaScript to TypeScript? I really would love to hear how other people did it.
Why did you do it, what techniques or ways did you use to make it painless and smooth? 😁
I have used TypeScript several times however in React. I was preparing my portfolio for the job hunt and I thought I might need something more. I didn't enjoy it and then didn't use it anymore.
Recently I have seen TypeScript almost everywhere and while planning to hop back to the job hunt again (after trying to find my first job with 300 resumes sent), I decided to take TypeScript more seriously.
I see TypeScript in many job listings, in my country (Georgia), as well as in many European countries and America, not sure about Asia. Seems like I do need it.
So, I decided to start with Vanilla JavaScript, instead of React because I have been targeting Vanilla first to strengthen the fundamentals. Also, I can write code but sometimes have a hard time really explaining it theoretically and that's what I need for interviews.

First, I spent 2-3 days reading the official documentation and making notes about everything. Then I re-read these notes several times and somewhere at 80% of the documentation I got bored. I am that person who falls asleep when reading. I usually learn faster from practice so I prepared some theoretical knowledge and started converting my JavaScript to TypeScript.
It was horrible! I hardly could use whatever I learned from theory, I forgot everything I wrote down and read and I got stuck. My goal was to try to read, remember, and then try to use that in knowledge. Nope.
In the end, my plan didn't work, I just started learning while fixing all the red lines and googling here and there. The first Vanilla project (very small) took me almost a day to convert to TypeScript because I had to google a lot but also read why I was doing this. I also used ChatGPT a lot to increase the time spent on coding instead of googling and filtering information. Seems like writing 2023 doesn't work for search anymore.
On the next day, I continued doing the same but then realized most of my projects were on React. So I found random projects on Github and started converting them to TypeScript. And started to become better and better.
My main idea was not to code from scratch and try to come up with all possible case scenarios for TypeScript but instead take the projects already made with Vanilla JavaScript and convert them to TypeScript. And working on other people's projects also could be an additional plus because I learned to read other people's code.
Today is going to be my 3rd day of practice and I was trying to analyze whether it is working or not.
Surprisingly, the case scenarios never end. I learned how to create interfaces but didn't create aliases yet, not sure why haha. Then used a lot of type assertions to work with the DOM, optional parameters, and of course, generics. Getting stuck with asynchronous functions at times but I do feel like it did get better. I am thinking of continuing this way and then switching to React in a similar way.


Latest comments (81)
javascript -> anyscript -> typescript
I'd recommend read some books which covers Object Oriented Programming & TypeScript. Only books cover ALL STUFF AT ONCE.
That's it. That is will be enough to figuring out all aspects of TypeScript
Great idea! Anything specific you would recommend?
I think the "JavaScript: The Definitive Guide" by David Flanagan maybe is the best solution for learning JS and TS from A to Z. And "Effective TypeScript: 62 Specific Ways to Improve Your TypeScript" by Dan Vanderkam will improve knowledge of TS more deeply
Thanks!
La transición de JavaScript a TypeScript implica seguir varios pasos clave para aprovechar las ventajas de TypeScript, que es un superset de JavaScript con tipos estáticos. Aquí tienes una guía general para realizar esta transición:
Instala TypeScript:
Comienza instalando TypeScript en tu proyecto Puedes hacerlo usando npm (Node Package Manager) con el siguiente comando:
Copy code
npm install typescript
Renombra tus archivos:
Cambia la extensión de tus archivos JavaScript de .js a .ts. Esto le dice a TypeScript que estos archivos contienen código TypeScript.
Configura el archivo tsconfig.json:
Crea un archivo tsconfig.json en la raíz de tu proyecto o utiliza el comando tsc --init para generar uno automáticamente. Este archivo de configuración permite definir las opciones de TypeScript para tu proyecto. Puedes personalizarlo según tus necesidades.
Annotación de tipos:
Comienza a agregar anotaciones de tipos a tu código JavaScript. TypeScript utiliza anotaciones de tipos para ayudar al compilador a comprender mejor tu código y proporcionar verificaciones estáticas. Por ejemplo, en JavaScript:
javascript
Copy code
function add(a, b) {
return a + b;
}
En TypeScript, puedes anotar los tipos de la siguiente manera:
typescript
Copy code
function add(a: number, b: number): number {
return a + b;
}
Resuelve los errores y advertencias del compilador:
Ejecuta el compilador TypeScript (tsc) en tu proyecto. A medida que agregues anotaciones de tipos, el compilador te alertará sobre errores o advertencias. Resuelve estos problemas siguiendo las indicaciones del compilador.
Aprovecha las características de TypeScript:
TypeScript ofrece muchas características adicionales, como interfaces, clases, módulos, y más. A medida que te familiarices con TypeScript, considera utilizar estas características para mejorar la calidad de tu código.
Integración con herramientas y bibliotecas:
TypeScript es ampliamente compatible con bibliotecas y herramientas de JavaScript. Asegúrate de que las bibliotecas que utilizas sean compatibles con TypeScript y busca tipos definidos (archivos .d.ts) para las bibliotecas si están disponibles.
Migración gradual:
No es necesario convertir todo tu proyecto a TypeScript de inmediato. Puedes migrar gradualmente, comenzando por las partes más críticas o nuevas adiciones al código.
La transición de JavaScript a TypeScript puede llevar tiempo, pero proporciona ventajas significativas en términos de detección temprana de errores, autocompletado en el IDE y mejor mantenibilidad a medida que tu proyecto crece.
Was introduced to TS via Angular.
That's a good start, I chose React so I had plenty of room without TS 😁
I started with this free course where I learned the absolute basics. Then I got the job where typescript was already used, so I was just learning from the existing codebase or looking up some new concepts in official documentation when needed
Ohh, thanks for sharing, I will check this out 🤩
My first programming languages were strongly typed languages - C++ and Java. While learning them I really disliked the 'strongly typed' aspect of them, and all the time wished that there was a way to declare and use variables without needing to specify their types. Then some years later, a savior came from above - JS. I was mindblown by the fact that you could create variables and functions without needing to specify their types. As I started learning and working with JS more and more, I noticed that a lot of errors began occuring related to incorrect types etc. So I realized that a dynamically typed language, although oftentimes useful, can also be a crutch. Then I discovered TypeScript and have since gained appreciation for typed languages and now use TS for all my projects. So I guess I went full circle. Working with JS and then TS allowed me to understand that type safety can be a real life saver and will prevent you from making many tiny silly mistakes that would take a while time to debug otherwise.
So lesson to take from this - be careful what you wish for!
Thanks for sharing your story, I never really thought about the experience from the other side when someone switched from strongly typed language to JS 😁 I didn't get the chance to fully understand if I like TS yet but while learning, I actually realized how many checks I needed to avoid possible errors and never really noticed before.
I work for a large company, but none of my colleagues use it. I just single-handedly began to start projects of small internal libraries that are used in our projects, written from scratch in TS, at first there was a simple tabs library, now a more serious dashboard project in Vue3+TS. In order to at least somehow move towards development, I took upon myself the responsibility to start writing on TS, thereby bringing my colleagues to the idea of what needs to be done. TS is no more a trendy thing - it is what the modern DEV world look like, we can't ignore the fact that this tool is useful and also rises the level of JS understanding too.
Thanks for sharing! Do you enjoy using TypeScript?
Love it. At very first i was struggling with it, but now i do understand what am i doing and what for, devtut.github.io/typescript/gettin...
That's great! I am a little getting used to it already 😁
Can't imagine life without it already lol. All the greatest repos on Github are already TS-only, so we have no choice but to learn typescript
Deno, witch Dahl develop after NodeJs is great i many way, but one it runs Typescript "out of the box" so you can do a deno run myfile.ts.
For me a great way to test and learn Typescript.
For me learning new concepts i like to get rid of all extra Steps och just focus on learning lets say Typescript.
So if you never more gone use Deno, it a great tool when focus on learning Typescript.
Someone already mentioned Deno, I will definitely check it out, thanks for sharing!
That's a very good idea to learn a language
I started using TypeScript a few years ago when my company took over an old Angular project. Since then, I've mainly used TypeScript for React. I didn't really dive into the official documentation much. At the beginning, I learned TypeScript mostly through libraries and frameworks' type definitions. I have to admit, I used "any" a lot back then.
But nowadays, I'm actively learning about new TypeScript features, helpful tips, and tricks by following some TypeScript pros on X/Twitter. I've also reduced my use of "any" in my codebase. However, I still use "any" for some shared libraries across the repo/project.
Thanks for sharing, good to know there is nothing wrong if it takes some time. Sometimes I felt like it's super easy to switch but seems like it depends a lot on experience and the language you are coming from + just other personal factors.