Skip to content

Instantly share code, notes, and snippets.

@cliffordfajardo
Last active December 5, 2022 15:15
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 cliffordfajardo/2af0a97185870f00926091d8dadd6383 to your computer and use it in GitHub Desktop.
Save cliffordfajardo/2af0a97185870f00926091d8dadd6383 to your computer and use it in GitHub Desktop.
typescript migration

Credits to Mike North Sr.Staff Engineer from LinkedIn’s UI Infra team for the inspiration for the stuff below 🙏

What not to do

  • functional changes at the same time
  • attempt this with low test coverage
  • publish your types for consumers while they’re in a weak state

Compiling in lose mode:

  • allow implicit any in your tsconfig # TODO show a breif code snippet example of value to change in tsconfig.
  • start with tests passing
  • careful to avoid changing behavior
  • rename all .js to ts
  • get tests passing again

Work towards squashing explict any’s …. Incrementally working towards removing explicit any’s

  • replace any’s with more appropriate types
  • try hard to avoid unsage type casts
  • ....once you’ve done that turn on ‘strict mode’ Incrementally
    • strictNullChecks: true,
    • strictFunctionTypes: true
# rename all JSX files in src/ to TSX (reactjs example)
find src -name '*.jsx' -exec bash -c 'git mv "$0" "${0%.jsx}.tsx"' "{}" \;

# rename all JS files in src/ to TS
find src -name '*.js' -exec bash -c 'git mv "$0" "${0%.js}.ts"' "{}" \;

# rename all JSX files in tests/ to TSX
find tests -name '*.jsx' -exec bash -c 'git mv "$0" "${0%.jsx}.tsx"' "{}" \;

# rename all JSX files in tests/__snapshots/ to TSX
find tests -name '*.jsx.snap' -exec bash -c 'git mv "$0" "${0%.jsx.snap}.tsx.snap"' "{}" \;

# rename all JS files in tests/ to TS
find tests -name '*.js' -exec bash -c 'git mv "$0" "${0%.js}.ts"' "{}" \;

when you make these changes

  • make sure your on a different branch so its easy to revert/delete changes
  • save your progress via commits so its easy to reset your code to a working state
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment