Skip to content

Let us slowly move to Typescript. (instructions inside) #4434

@ghost

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.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions