Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save znseaman/6afdac05447cf33a2b65cdad7391c93b to your computer and use it in GitHub Desktop.
Save znseaman/6afdac05447cf33a2b65cdad7391c93b to your computer and use it in GitHub Desktop.
Transitioning an Existing Project from JavaScript to TypeScript

Transitioning an Existing Project from JavaScript to TypeScript

by Zachary Seaman

Transitioning an existing project to TypeScript seems tough. In this post, I will show a 3 step plan to do so without disruption or undue stress.

A couple of warnings before we get started. First, improve low test coverage to ensure project stability during the transition. Second, refrain from functional changes to verify the project isn’t working because of TypeScript and not a recently introduced bug. With the warnings out of the way, let’s jump in!

From the “TypeScript 3 Fundamentals” course on Frontend Masters, the instructor Mike North laid out a 3 step plan as follows:

  1. Rename file extensions from .js to .ts and fix type errors
  2. Declare explicit any types by setting “noImplicitAny”: true in the tsconfig.json and narrow down the types where TypeScript complains.
  3. Slowly enable strict mode by setting each of the following options in the tsconfig.json: ”strictNullChecks”: true, ”strict”: true, ”strictFunctionTypes”: true, ”strictBindCallApply”: true and fixing each error as necessary.

After completing each step with passing tests, submit a pull request to delineate each step and stay on track. And that’s it!

By ratcheting up type strictness, the transition from JavaScript to TypeScript isn’t so hard after all.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment