-
Notifications
You must be signed in to change notification settings - Fork 3.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Let us slowly move to Typescript. (instructions inside) #4434
Comments
@thinkpadder1 thanks for the notes on Typescript. In the future, we would prefer that you start a discussion on the forum for something like this. Given its incredible impact, it will require significant discussion. For now, we'll have to table the discussion as we are heads down on 3D Tiles, but I have labeled this In the meantime, you might want to research how this would affect Node.js users of Cesium and how the transpiler would impact development; the core dev team will insist on a smooth dev experience with virtually no overhead. |
Thanks for the list of resources and getting started details @thinkpadder1. I would love to move to something like TypeScript and I know @kring is a bing proponent as well. It will be a non-trivial effort and I agree with @pjcozzi isn't not something that can happen until the 3D Tiles work is done (given the amount of new code that that branch will introduce and the amount of time to get the team used to working in TypeScript). It's definitely something I would start prototyping at a hackathon or when I suddenly have free time if no one beats me to it. My main concerns are testing, coverage, performance, and backwards compatibility with existing Cesium applications. I also wouldn't mind surveying the JS landscape and see what possible benefits TypeScript would provide over other approaches, like Babble and flow. I'm fairly confident that TypeScript will win out here, but we need to do our due diligence. |
I spent a bunch of time looking at using TypeScript for TerriaJS. The main problem with it was the ecosystem. You can't use jsdoc or eslint, for example. Similar tools for TypeScript are far less mature. In many cases, tools that initially looked promising were expecting older versions of TypeScript and hadn't been updated in many months. I even tried ugly hacks like having the TS compiler generate JavaScript with comments and then running that through jsdoc, but I couldn't get it to work reliably. This was probably 8 months ago now, so maybe things have improved. Unfortunately, IMO, the ecosystem matters just as much if not more than the language. In the end we ended up going with ES2015 and Babel. We haven't really tried Flow yet, but it looks pretty good. |
Thanks @kring those were exactly the types of problems I was worried about. Even if things have improved, it shows that this is actually a major change for our code and definitely will require lots of thought and planning. As an aside, since you went with 2015 and Babel, are you using modules? How does testing and coverage get handled with transcompilation? |
@kring For linting, see TSLint. Typescript supports JSDoc style comments and works great in Visual Studio Code. Even if you don't use Typescript, it's a great editor with the Salsa service. There are even extensions that will generate most of the JSDoc for you: Document This Here is a list of all currently supported JSDoc annotations (which is being actively worked on). Lastly, someone is working on a JSDoc to Typescript Definitions plugin and he is targeting Cesium + OpenLayers: jsdoc-typescript-plugin. It could be the middle ground between sticking with what Cesium has and fully committing to Typescript (at the bare minimum, it would help people using Cesium). |
@thinkpadder1 yeah I had previously discovered TSLint, as well as typescript-eslint-parser. It looks like both have made some progress since I've looked, but still aren't nearly mature as ESLint with Babel. re: doc, those things are all nice, but they don't help us generate the documentation on cesiumjs.org: http://cesiumjs.org/refdoc.html |
@kring Have you guys looked at TypeDoc? Cloudflare uses it: Generating Documentation for TypeScript Projects The post shows how to use it and compares it against JSDoc. |
Any update on this? |
As of Cesium 1.70.0, we are shipping official TypeScript definitions. If you want to read all of the gory details, and potential future plans for TypeScript and CesiumJS, check out this blog post: https://cesium.com/blog/2020/06/01/cesiumjs-tsd/ Sometime over the next week or so, I'll be consolidating any TypeScript issues into a new master issue for plans going forward. Thanks! |
@mramato I think that you meant we are shipping 😄 |
Whoops, thanks. It was supposed to say "now shipping" fixed 😄 |
I keep running into annoyances or "pain points" when working in CesiumJS in VSCode with regards to typings. Intellisense relies on the TS Server but our JSDoc reliant setup gives it many issues. In no particular order, an incomplete list of recent pain points I've noticed with types:
If you want to see more just turn on Typechecking in VSCode for JS with the CC @ggetz |
I'd like to disagree here. In fact, I've previously been advocating for an access modifier that is stronger than (Originally, this referred to Java. There, the question about the "internal to the library" is handled more cleanly, with the "default" visibility: When something is neither Now, what should be the purpose of "stronger than Using some random code snippets from some class in CesiumJS (the context doesn't matter): boundingVolume: {
get: function () {
return this._boundingVolume;
},
},
boundingSphere: {
get: function () {
return this._boundingVolume.boundingSphere;
},
}, Nice and straightforward: You can call I could now mention that the caller could, in fact, just write Beyond that: You don't know that these lines are not just propery accesses, but actually calling 'getters'. That 'getter' could do anything. At the call site, you have zero chance of knowing what this line does, and (worse) zero chance of figuring that out (except for a debugger run...). So much about language bashing 😁 Imagine that this 'getter' actually does more than just returning the property. Imagine that it is refactored to something like this: boundingVolume: {
get: function () {
if (this._boundingVolumeWasModified ) {
this._boundingVolume = update();
this._boundingVolumeWasModified = false;
}
return this._boundingVolume;
},
}, A pretty common "dirty flag" was introduced. Fortunately, this change is hidden from the users. Callers who did But the point is that even within the class, there is an inconsistency now: The Some pseudo-spec here could be: const s0 = thing.boundingSphere;
const s1 = thing.boundingVolume.boundingSphere;
assertEquals(s0, s1); and this one would break now. If the getter was implemented as boundingSphere: {
get: function () {
// NO: return this._boundingVolume.boundingSphere;
// YES, use the 'boundingVolume' getter:
return this.boundingVolume.boundingSphere;
},
}, then the state would remain consistent. |
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:
Rename all js files in the pattern below (except the ones with "!") to .ts (taken from gulpfile.js):
I just went in the directories (not the "!" ones) and ran the recursive command:
Use the Typescript watcher to automatically compile Typescript to Javascript upon changes:
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.
The text was updated successfully, but these errors were encountered: