Let us slowly move to Typescript. (instructions inside)
- Dominant language
- JavaScript
- Stars
- 15.7k
- Forks
- 3.9k
- Avg merge
- 4d 6h
- Merged PRs (30d)
- 34
Description
I set up Typescript pretty easily with Cesium (with minimal friction).
1. Install Typescript:
`
npm install --save-dev typescript
`
2. Create a file in the root directory **tsconfig.json**:
```
{
"compilerOptions": {
"target": "es3",
"module": "amd"
},
"include": [
"./Source/**/*.ts"
]
}
```
3. 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/' '{}' \;
```
4. Use the Typescript watcher to automatically compile Typescript to Javascript upon changes:
```
tsc -w -p .
```
5. 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.
- [Typescript with Gulp](https://www.typescriptlang.org/docs/handbook/gulp.html)
- [Migrating from JavaScript](https://www.typescriptlang.org/docs/handbook/migrating-from-javascript.html)
- [Incrementally Migrating JavaScript AMD Project to TypeScript](https://dzone.com/articles/incrementally-migrating-javascript-amd-project-to-1)
- [Compiler Options](https://www.typescriptlang.org/docs/handbook/compiler-options.html)
Contributor guide
Research direction
Start with gulpfile.js and the existing Source/**/*.js pattern, paying attention to the listed Worker exclusions. Review the proposed tsconfig.json settings and the tsc -w -p . workflow, then check the TypeScript migration references linked in the issue. Done means the project can incrementally compile the intended Source files while preserving the current build process.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript, typescript
- Domain
- build-system, developer-experience
- Issue type
- Refactor
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 30/100