Typescript integration in GDJS

Well, @arthuro555, @bouh, and I are pretty much interested in converting the GDJS codebase to Typescript because of how easy it is to prevent bugs and its highly maintainable. Let me know what you think of it @4ian, Then we may further discuss the details here.

Cheers :slight_smile:

Clarification: I am for typescript definitions in GDJS, not for converting the codebase. For the IDE I don’t know flow enough to be able to juge if it is better or not, and converting GDJS to complete TS is not the best IMO as adding some kind of compilation step might bring to less optimized code.

1 Like

that was a typo sorry; i wanted to write GDJS

For now we want to keep JavaScript files with Typescript annotations in GDJS (see this document) - because:

  • There is no bundling or compilation for GDJS, which allow to keep the development iteration speed fast.
  • It’s also simpler as we don’t have to run a bundler/minifier in GDevelop itself.
  • The game engine is already documented with JSDoc annotations, and Typescript is able to understand these annotations (or augment them).

The subject of minifying the source code is still subject to discussion and improvement :slight_smile: For typing, if we can avoid the cost of being forced to run typescript, it’s better.

There are a few disadvantages to this way of doing this, namely:

  • you have to be careful about not declaring global variables.
  • some features like “fat arrows” can’t be used, unless you’re sure you’re not targeting Android 4.4, so code is more verbose.
  • some typing from Typescript can’t be reproduced with JSDoc.

While we can review this later, for now you can totally help by adding more typescript/jsdoc annotations to the files that don’t have them. To start, find a file without a // @ts-check at the top, then fix it :smiley:
See https://www.typescriptlang.org/docs/handbook/type-checking-javascript-files.html#supported-jsdoc for information about typescript support in JS.

We also need to update Typescript to latest version (3.9) for GDJS (run npm run check-types in GDJS). Unfortunately it seems to error because of variables declared as @private or @protected… because TS don’t understand properly these when there is a class made in ES5 style (with a function constructor and prototype methods) :’( (It would work with a ES6 class - but it’s not well supported in old browsers).
Your help/investigation here would be welcome :slight_smile:

1 Like

Example of improving typings: Improve autocompletions for JavaScript code events and for the game engine by 4ian · Pull Request #1761 · 4ian/GDevelop · GitHub :slight_smile:

1 Like