Keywords: TypeScript
This is the lab project to demonstrate how to migrate a JavaScript project into TypeScript project step by step.
The project TaskMe
is a very simple task management API service built by LoopBack. It was originally written in JavaScript. To "tsify" it, there are a few branches from tsify-original
to tsify-misc
, where each branch represents a certain stage on the migration path. By hitting the GitHub Compare changes view, you can see the difference between each two branches.
Please check the below instructions to learn how to play with it.
You can also find the online slides here, where it discussed:
- Why TypeScript is so popular?
- What is TypeScript? (by a few demos)
- How to tsify?
And the video series recorded for the slides.
For more lab projects from MorningSpace Lab, please check morningspace.github.io.
The very beginning stage. No TypeScript at all.
This is the basic use of TypeScript. You can start to write TypeScript without changing any of your existing code. By adding type declaration files of project dependencies, you can enjoy auto-completion and code navigation when you call your dependencies. You can also get early benefits by trying to enable a few options in tsconfig.json, e.g. noImplicitReturns, noFallthroughCasesInSwitch, etc.
Start to transform some JavaScript src files into TypeScript src files w/o big effort. Just simple rename and probably some tweaks in tsconfig.json to avoid tsc complains.
Transform more JavaScript src files into TypeScript src files, add more TypeScript features incrementally, and use TypeScript more deeply. It normally requires some adjustments in the source code and tweaks in tsconfig.json.
Complete migration to TypeScript project, add tslint for lint check, nyc for code coverage, debug settings in vscode for TypeScript debugging, etc.
Some typical errors can be seen as below when do the transformation.
The simplest resolution to this issue is to define the type 'xyz' as any. Of course you can define interface if it deserves. Keep in mind, whenever you use any, you lose out on most of the error checking and editor support that TypeScript gives you.
This is caused by the use of let or var when require external module. Use ES6 syntax, the import statement instead.
Add "es2015" in "lib" settings in tsconfig.json.
Since TypeScript 2.9, JSON file import has been well supported by enabling resolveJsonModule in tsconfig.json. See: https://blogs.msdn.microsoft.com/typescript/2018/05/31/announcing-typescript-2-9/#json-imports