You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Item 82: Convert Module by Module Up Your Dependency Graph
Things to Remember
Start migration by adding @types for third-party modules and external API calls.
Begin migrating your own modules from the bottom of the dependency graph upwards. The first module will usually be some sort of utility code. Consider visualizing the dependency graph to help you track progress.
Resist the urge to refactor your code as you uncover odd designs. Keep a list of ideas for future refactors, but stay focused on TypeScript conversion.
Be aware of common errors that come up during conversion. Move JSDoc types into TypeScript type annotations if necessary to avoid losing type safety as you convert.
Code Samples
asyncfunctionfetchTable(){constresponse=awaitfetch('/data');if(!response.ok)thrownewError('Failed to fetch!');returnresponse.json();}
classGreeting{constructor(name){this.greeting='Hello';// ~~~~~~~~ Property 'greeting' does not exist on type 'Greeting'this.name=name;// ~~~~ Property 'name' does not exist on type 'Greeting'}greet(){return`${this.greeting}${this.name}`;// ~~~~~~~~ ~~~~ Property ... does not exist}}
conststate={};state.name='New York';// ~~~~ Property 'name' does not exist on type '{}'state.capital='Albany';// ~~~~~~~ Property 'capital' does not exist on type '{}'
// @ts-check/** * @param {number} num */functiondouble(num){return2*num;}double('trouble');// ~~~~~~~~~// Argument of type 'string' is not assignable to parameter of type 'number'