-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Description
Typescript is powerful, expressive, and very good for collaborative projects. Community support and ecosystem are good for React projects.
Adding it to this codebase, may reduce typos and parameter type errors. New contributors will be a little more relaxed to modify existed code.
I assume there can be some phases for this approach.
Phase 1
Almost painless.
- Add a
tsconfig.jsonwithallowJs: trueand some other compilerOptions to avoid countless strict errors. - Install several
@types/*packages. If you're using VSCode, IntelliSense will work pretty good already.
Phase 2
Do some filename converting, from js->ts.
- May need to upgrade webpack toolchain to use the latest ts-loader. Or upgrade to [babel@7].(https://devblogs.microsoft.com/typescript/typescript-and-babel-7/) for compiling ts modules.
- Install some packages to make sure
avaandjestcan load ts modules.
Phase 3
Rewrite react components, from js->tsx, will get a lot of errors at first, but anything typed will always make future maintainance a little bit easier. And I assume there may already be some useful codemods or transformers to automate this process.
Rewriting(since phrase 2) is not mandatory, and even after it starts, we can still keep a mixed codebase of js/ts, and recommend to write new code in ts/tsx.