We converted 350 CoffeeScript files into TypeScript. This is how we did it.
We are converting CoffeeScript to TypeScript with a combination of CoffeeScript v1, CoffeeScript v2, and Decaffeinate. From left to right, the transpilers/compilers become more readable and less reliable. Therefor, we are using Decaffeinate whenever possible and falling back to CoffeeScript v2 and then v1. Once the CoffeeScript has moved entirely to TypeScript, our plan is to go back over the files that did not use Decaffeinate, and given them some individual attention.
Our process has been to convert categories of files, about ten files at a time. After each batch of ten, we build, run tests, and fix problems. We have been committing to master in conversion categories; for instance, one commit is the conversion of
src\deferred, the next commit is of
src\effects, et cetera.
This is how it looked from the command line:
# Prepare the branch and commit. git checkout -b convert-src-deferred-to-TypeScript git commit -m "Convert src/deferred to TypeScript" # Repeat the following until src/deferred is all TypeScript. .\convert-coffee-to-type-script.ps1 npm run build # Then open editor to fix errors. npm run test # Then open editor to fix errors. git add -A git commit --amend --no-edit # Then, open up a pull request for review, if appropriate. # After approval, merge into master. git checkout master git merge convert-src-deferred-to-TypeScript --no-ff
Some Logic Errors
- Duplicate identifiers. Delete them.
- Undefined functions. Delete the call.
expect(false === true). Fix the test.
- When we imported them with
require, objects exported with
export defaulthad a top level
Some Conversion Errors
It also found the following conversion problems. These conversion problems are due to the transpilation not due to human error.
// error TS1192: Module '"chai"' has no default export. import chai from 'chai'; // solution import * as chai from 'chai';
The PowerShell Script
This is the
convert-coffee-to-type-script.ps1 PowerShell script that we used.