Skip to content
This repository was archived by the owner on Mar 13, 2023. It is now read-only.

Codebase migration to TS using codemods #188

Merged
merged 8 commits into from
Jul 14, 2022
Merged

Codebase migration to TS using codemods #188

merged 8 commits into from
Jul 14, 2022

Conversation

mtfranchetto
Copy link
Contributor

Details

Following an approach used by Airbnb (highlighted here) using ts-migrate the codebase have been automatically converted to Typescript.
This has several advantages:

  • consistency, no mix of Javascript and Typescript
  • Typescript features can be used in every part of the codebase without any manual intervention
  • less "noise" in pull requests when refactoring old parts of the project
  • it's faster to fix a typing mistake in an already converted codebase rather than reworking multiple files at the same time.

The tool did the best to convert the codebase by fixing all the auto-fixable errors but some typing errors are left commented, especially function with unclear signatures and React component props, to allow TS compilation to run smoothly.
If a developer fixes a function signature they can run npm run ts-reignore (as stated in the readme) to let ts-migrate remove some unnecessary comments, making it a very versatile tool, useful not only for the bootstrap phase but also during development.

Refer to the linked article to know more about ts-migrate and all the changes applied during the conversion.

Full ts-migrate output

TypeScript version: 4.7.4
Ignoring sources from tsconfig.json, using the ones provided manually instead.
Initialized tsserver project in 242ms.
Start...
[strip-ts-ignore] Plugin 1 of 14. Start...
[strip-ts-ignore] Finished in 138ms.
[hoist-class-statics] Plugin 2 of 14. Start...
[hoist-class-statics] Finished in 4ms.
[react-props] Plugin 3 of 14. Start...
[react-props] Finished in 108ms.
[react-class-state] Plugin 4 of 14. Start...
[react-class-state] Finished in 1ms.
[react-class-lifecycle-methods] Plugin 5 of 14. Start...
[react-class-lifecycle-methods] Finished in 1ms.
[react-default-props] Plugin 6 of 14. Start...
[react-default-props] Finished in 1ms.
[react-shape] Plugin 7 of 14. Start...
[react-shape] Finished in 1ms.
[declare-missing-class-properties] Plugin 8 of 14. Start...
[declare-missing-class-properties] Finished in 8.1s.
[member-accessibility] Plugin 9 of 14. Start...
[member-accessibility] Finished in 2ms.
[explicit-any] Plugin 10 of 14. Start...
[explicit-any] Finished in 26.7s.
[add-conversions] Plugin 11 of 14. Start...
[add-conversions] Finished in 11.6s.
[eslint-fix] Plugin 12 of 14. Start...
[eslint-fix] Finished in 2.5s.
[ts-ignore] Plugin 13 of 14. Start...
[ts-ignore] Finished in 21.8s.
[eslint-fix] Plugin 14 of 14. Start...
[eslint-fix] Finished in 958ms.
Finished in 1m 12.2s, for 14 plugin(s).
Writing 52 updated file(s)...
Wrote 52 updated file(s) in 7ms.

Testing

Tried different parts of PCM and they work the same as before, including the wizard.

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants