explorer
explorer copied to clipboard
Proposal: Migrate to TypeScript
Reasons
I have gone through a reasonable amount of the codebase and I have seen that there is a need to improve the development experience and code quality. TypeScript is better suited for building and managing large-scale applications with multiple teams.
- It checks the code for errors and warnings before you run it.
- It static typing feature will reduce the number of errors at build time; hence better developer experience.
- There will be no need for
prop-types, type checking feature will take care of this. - It makes code easier to read, maintain, and debug, and can also help reduce the risk of security vulnerabilities.
- It provides extra tooling and features like interfaces, classes, namespaces, generics, etc.
Proposal
- Migration can be done in parts since existing JavaScript code will still run in TypeScript.
- TypeScript code must not be strictly typed as the migration starts. Changes can be made as it progresses. For example, tests can still be left as JavaScript code.
Ah yes this does indeed sound like a very good idea. As a matter of fact for newer projects we have started building them in typescript from the beginning.
If you would like to take a stab at starting the migration to typescript that would be fantastic!
I wanted to share my plan for the migration.
- Set up TypeScript: Install TypeScript and Create a
tsconfig.jsonfile to configure TypeScript. - Rename the
.jsfiles to.tsx. I will start with thecomponentsfolder and move to others. - Update dependencies: Some third-party libraries have TypeScript typings available. I will Install these typings (e.g., @types/package-name). If typings are not available, I may need to create custom type definitions or leverage TypeScript's
anytype for those libraries. - Type annotations and interfaces: Gradually add type annotations to the codebase using interfaces or type aliases.
- Compile and test: Run tests to ensure the migration hasn't introduced any regressions or bugs.
- Refactor and optimize.
- Iterate and repeat from step 2 as I move from one folder to another. Push code with migration done per folder.