The Path to TypeScript
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.
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.
Error TS2339: Property 'abc' does not exist on type 'xyz'.
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.
Error TS2451: Cannot redeclare block-scoped variable 'xyz'
This is caused by the use of let or var when require external module. Use ES6 syntax, the import statement instead.
Error TS2693: 'Promise' only refers to a type, but is being used as a value here
Add "es2015" in "lib" settings in tsconfig.json.
Error TS2307: Cannot find module 'your/path/to/something.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