Why TypeScript Migrations Fail

preview_player
Показать описание
In this video, we're looking at why a lot of developers struggle with TypeScript migrations and how you can avoid any potential pitfalls. One common mistake is trying to convert too much code at once, which can slow down feature work and lead to failure. The solution is to break it up into smaller chunks that don't impact ongoing development. Another error is migrating files in the wrong order, which can cause errors and force you to use "any" types all over the place just to get things working. You must avoid importing JavaScript files into TypeScript files without converting them first. These are just a couple of the reasons why TypeScript migrations can fail. By understanding these pitfalls, and taking a cautious, problem-solving approach to TypeScript migration, you can ensure a smooth transition to TypeScript.

Become a TypeScript Wizard with my free beginners TypeScript Course:

Follow Matt on Twitter

Join the Discord:

Рекомендации по теме
Комментарии
Автор

You forget the one where you are the only one actually doing migration, the rest of the team just simply doesn't care.

fulconandroadcone
Автор

I believe there is a little script somewhere that analyses your imports, works out leaf files (eg, ones that don't have no project imports, only package modules),
Then sorts by size, and then works up the tree again finding files that only import the previously scheduled files. And so on and so on.
Gives you a itinerary of what order to upgrade your files.
I believe it does some counting on functions and variable counts also.
But can't remember.

ColinRichardson
Автор

The worst hurdle to our React project was Redux. Our redux code was a huge portion of the project, but the entire redux store positions itself as a dependency of _everything_. This makes the advice of converting the dependency tree from the leaves up very hard to apply. Often times we resorted to using ts-expect-error in a few places instead of trying to understand wtf the redux code was doing (which often was... not much).

jeralm
Автор

I’m halfway through the massive PR. welp too late to turn back now :D

ENI
Автор

I don't get it. If it's a partial migration, by definition you're either importing JS into TS, or TS into JS. You say the former is a recipe for disaster, but the latter is straight up not possible lol.

loucadufault
Автор

My early migrations failed because the patterns I was using were incompatible with typescript style thinking.

curiouslycory
Автор

Lint, type check, test, check formatting before pushing anything

dheerajsinghnagdali
Автор

You forget the part where we define types too much instead of letting typescript do the work. And resulting code becomes so much cluttered with types

leetkhan
Автор

There were files I had as a dependency and I knew It would take a while for me to convert especially when it itself had other dependencies. So as a temporary measure I created an interface under a custom namespace so I would know in the future what to convert

abdallahm
Автор

This seems like it would be much easier if Typescript had a 'baseline' feature, like Psalm and PHPStan do for PHP. I.e. let you acknowledge that there are many type errors in your codebase, keep a list of them in your repository, and make sure that you can't accidentally add any new ones.

But maybe a baseline wouldn't work as well in TS because TS has much more extensive type inference than the PHP tools do, so an error in one place can directly affect much further reaching parts of the code as the compiler sees it. PHP tools pretty much never infer function types, they're either explicitly stated or they're treated as something like any/unknown.

barneylaurance
Автор

1. Write thousands of tests
2. Migrate to mono-repo
3. Rewrite the packages one by one to TS
4. Enjoy

This is how I did it several years ago (=

i.reutenko
Автор

What do you think about gradually migrating either by using JSDoc types or simply renaming JS files to TS files without initially editing them?

barneylaurance
Автор

How do you recommand to do for a success migration ? We are facing this problem by converting our design system fully Js to typescript 😢

jimmyj.