Skip to content

[Tracking Issue] Typing and proper usage of modern TypeScript features #94

@Jartreg

Description

@Jartreg

The project technically uses TypeScript, but most things aren't strongly typed yet. In addition to that, there are many parts that look pretty weird when considering modern and idiomatic TypeScript conventions. This is why I would like to help with and advocate for proper strong typing and usage of modern TypeScript features.

This issue is intended to track the progress (if it is approved).

To get the project into the desired state, following steps would be necessary in the long term:

  1. Adding strong types to existing interfaces
    • Types like any should only be used where it is explicitly necessary.
    • No implicit any in function declarations
    • The end goal would be to enable TypeScript's strict mode across the project.
  2. Converting existing code and interfaces to idiomatic typescript
    • Proper use of ES classes
    • Replacing the old JS module pattern or static-only classes with ES modules (e.g. in ide.ts and lang/index.ts)
    • Going further (optional?): using inversion of control and readonly more
      For example the interpreter services could be interfaces with different implementations instead of reassigning certain methods in tests or docs. The interpreter would be passed the implementation once at construction time.

Benefits

  1. Strong typing detects many errors at compile time instead of when it's too late
  2. Most editors can give very high quality suggestions, improving maintainability (idk what editors most contributors use and how easy it is to set up a TypeScript lang server with them)
  3. Modern ES syntax is less verbose that older patterns, making it easer to read
  4. ES modules offer the desired isolation and can be split up with little effort when necessary
  5. (Regarding IOC and readonly):
    • assigning a non-null value at construction time eliminates the otherwise necessary null-checks and non-null-assertions (!)
    • readonly avoids unexpected writes to properties when something is not expected to change

Drawbacks

  1. TypeScript was quickly suggested and the initial "conversion" didn't add types for most things and used any extensively. I don't know how comfortable most contributors are with TypeScript and whether they really want to use it that extensively. In addition, I am biased in favour of it since I use an editor that doesn't need any setup for proper TypeScript support with suggestions and everything.

  2. Interop
    The conversion of some internals in step 2 will add further differences to what the tools on the E-learning platform expect. Since these tools heavily use the parser's and interpreter's internals and are strictly speaking not public (e.g. as a user I can only know about isRecursive, hasStructure and so on), more effort in keeping them compatible would be needed.

    So far I see two ways to approach this:

    1. Add tests to verify their compatibility to this repository and add more emulation to the interop export
    2. Move them to this repository entirely to keep them up to date directly

I'd expect this to take quite some time and I wouldn't want to rush this (that's why I created this issue). What are your thoughts on this?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions