-
Notifications
You must be signed in to change notification settings - Fork 3.7k
Description
I set up Typescript pretty easily with Cesium (with minimal friction).
-
Install Typescript:
npm install --save-dev typescript -
Create a file in the root directory tsconfig.json:
{ "compilerOptions": { "target": "es3", "module": "amd" }, "include": [ "./Source/**/*.ts" ] } -
Rename all js files in the pattern below (except the ones with "!") to .ts (taken from gulpfile.js):
['Source/**/*.js', '!Source/*.js', '!Source/Workers/**', '!Source/ThirdParty/Workers/**', 'Source/Workers/createTaskProcessorWorker.js'];I just went in the directories (not the "!" ones) and ran the recursive command:
find . -name "*.js" -exec rename 's/\.js$/.ts/' '{}' \; -
Use the Typescript watcher to automatically compile Typescript to Javascript upon changes:
tsc -w -p . -
The resulting Javascript files will be placed next to the ts files. This will let us keep our current build process and reap the benefits of Typescript with minimal effort. We can just use a .gitignore for the js files. gulp-typescript does exist (see link at bottom).
Remember that Typescript is a superset of Javascript. Therefore, all of our current code works completely fine. Now, we can incrementally migrate. With type-checking, compiler options like strictNullChecks, noImplicitAny, noImplicitReturns, and much more (see link below), a proper module system with import/export, we can create new features faster and find dormant bugs (with type checking). Also, less tests! We don't have many contributors... so Typescript would definitely help. And you can finally use a proper IDE with autocomplete and refactoring tools.
We can complicate the build process with gulp-typescript and more, but I want us to start with the bare minimum first so we don't scare anyone away. Minimal friction is the keyword here.