Initial TypeScript setup and conversion (CJS to ESM, ES5 class functions to ES6 classes)#707
Open
ericyhwang wants to merge 8 commits intotypescriptfrom
Open
Initial TypeScript setup and conversion (CJS to ESM, ES5 class functions to ES6 classes)#707ericyhwang wants to merge 8 commits intotypescriptfrom
ericyhwang wants to merge 8 commits intotypescriptfrom
Conversation
…ttached to the class functions for better codemod porting
…ment out TS rulesets
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Set up TypeScript, do file renames from *.js to *.ts, then run codemods to convert CommonJS to ES modules and ES5 class functions to ES6 classes.
This is a redo of #705 without the dev dependency upgrades, which I moved out into #706 and are already merged into master. The one bigger difference here is that I updated the codemod handling of non-function prototype properties, e.g.
Backend.prototype.MIDDLEWARE_ACTIONS, by declaring them as fields and doing the assignment instaticblocks to reduce the diff size.Goals
It targets the
typescriptbranch, which we can use to stage the TypeScript changes until they're ready to merge into main. Making smaller intermediate PRs into that branch will make things easier to review.For now, my goal with the
typescriptstaging branch is to end up with TS source code that compiles into JS output compatible with the current JS source, so we could publish it a minor version. In a future major version, we can choose to update the compile target to drop ES5 support, especially if we want to start using things like async/await without the extra verboseness of downleveling.We should probably major version soon anyways, since Node 18's been EoL for a year, and Node 20's about to reach EoL.
Reviewer tips and notes
typescript-initialbranch down and locally view the commit's diff, e.g. in your editor.typescript-cjs-class-codemods-js-outputsbranch, in commit 5cad709. Similarly, it's better to pull the branch and compare locally.Let me know if you want to schedule time to go through this on a call!
Changes
lib/**/*.jsfiles tosrc/**/*.tswith no changesgit blameand other history spelunking tools on the "new" TS files.module.exportsstatements up. Some class JSDoc comments were attached to themodule.exportslines. Moving them so the comments are attached to the class functions means the codemod (next step) can do a better job porting the comments over to the ES6 class.Next steps
First thing after this PR is to go through the many TS compilation errors and fix them. Most fall into these categories:
extendsThen it'll be adding stronger types, likely based on our DefinitelyTyped definitions; doing more cleanup as needed; and converting test files to TS.