Skip to content
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

Adopt TypeScript #398

Open
thewilkybarkid opened this issue Aug 19, 2021 · 1 comment
Open

Adopt TypeScript #398

thewilkybarkid opened this issue Aug 19, 2021 · 1 comment

Comments

@thewilkybarkid
Copy link
Member

Currently, TypeScript is partially used on the backend, without type checking (@parcel/validator-typescript is a dependency, but isn't enabled). All files should be TypeScript (including the frontend etc), with strict mode enabled and types actually checked.

thewilkybarkid added a commit that referenced this issue Sep 7, 2021
Remove use of a forked dependency. The fork appears to add in an 'optional' option, which is undocumented and seemingly untested. It seems to work without it too.

The dependency has seen some updates, too, including TypeScript changes required for using strict mode (CyriacBr/class-fixtures-factory#10).

Refs #406, #398
thewilkybarkid added a commit that referenced this issue Sep 7, 2021
thewilkybarkid added a commit that referenced this issue Sep 7, 2021
thewilkybarkid added a commit that referenced this issue Sep 7, 2021
It's unused and appears to do nothing anyhow.

Refs #397, #398
thewilkybarkid added a commit that referenced this issue Sep 7, 2021
This change resolves some incorrect types, which don't trigger problems unless TypeScript is in a stricter mode.

Refs #398
@thewilkybarkid
Copy link
Member Author

One particularly troublesome line is

return Object.values(entities[type].prototype.__meta.properties).reduce(

It seems to be relying on the ORM having added a __meta property to the prototype, which is all completely untyped (and so clearly a hack). It seems possible to find it for an entity (using wrap()), but not for the prototype. It's possible you could find it out through the ORM's metadata storage (not tried yet), but I haven't really got a clue what this code is trying to achieve anyway. It feels like there's a far bigger problem to solve.

thewilkybarkid added a commit that referenced this issue Sep 8, 2021
Use of the 'any' type is dangerous and can easily result in bugs.

Refs #398
thewilkybarkid added a commit that referenced this issue Sep 8, 2021
The use of 'unknown' is better than 'any' because it's at least type-safe, but this should set the correct type.

Note this doesn't fix all the typing problems in this code.

Refs #398
thewilkybarkid added a commit that referenced this issue Sep 10, 2021
The IntlProvider has a required 'locale' setting; this didn't cause an error but make the console noisy while developing.

Refs #398
thewilkybarkid added a commit that referenced this issue Sep 16, 2021
Persona avatars are loaded, but the component expects them to be a data URI string rather than a Buffer object. As a result, the browser tries to load `/[object%20Object]`.

Images inlined in the API are one of the leading performance problems. Rather than try and fix the types so that avatars show consistently, this hides them completely where they don't work. As far as I'm aware, there's been no complaints that they're not displayed, and this will help make some of the critical pages a bit less slow.

Refs #392, #398
thewilkybarkid added a commit that referenced this issue Oct 12, 2021
__dirname is a Node.js environment variable that contains the path to the module's directory. It's currently redefined to be the current working directory, which is somewhat unexpected. This change removes it as path.resolve() uses the current working directory anyway.

Refs #398
thewilkybarkid added a commit that referenced this issue Oct 12, 2021
While there aren't any Jest tests yet, this change sets up ts-jest so we can write tests in TypeScript.

Refs #388, #398
thewilkybarkid added a commit that referenced this issue Oct 22, 2021
If the frontend isn't available (probably not possible yet, but will be when testing the backend directly), there will be no response body. This change makes sure it's stream-like before trying to do so.

Refs #388, #398
thewilkybarkid added a commit that referenced this issue Oct 22, 2021
As Parcel processes each file individually, TypeScript needs to be aware to disable incompatible types. Also, ts-jest needs to have type-checking disabled (since they don't currently pass).

Refs #398, https://parceljs.org/languages/typescript/#isolatedmodules
thewilkybarkid added a commit that referenced this issue Oct 27, 2021
thewilkybarkid added a commit that referenced this issue Oct 27, 2021
thewilkybarkid added a commit that referenced this issue Nov 1, 2021
thewilkybarkid added a commit that referenced this issue Nov 2, 2021
ESLint appears on only lint .js files by default.

I expect this CI build to fail as it reveals linting problems in TypeScript files.

Refs #398, #422
thewilkybarkid added a commit that referenced this issue Nov 2, 2021
I'm not sure why @typescript-eslint/typescript-estree has been used: I can't see any useful information about it. All documentation points to using @typescript-eslint/parser, which has been installed already. The only noticeable difference is that it doesn't understand when a type has been used, leading to @typescript-eslint/no-unused-vars errors.

I've added a separate TypeScript config file that includes all files in the codebase, as the new parser will error if it tries to load a file that hasn't been included.

Refs #398, #422, ba132cc
thewilkybarkid added a commit that referenced this issue Nov 2, 2021
thewilkybarkid added a commit that referenced this issue Nov 4, 2021
This change enables TypeScript's strict mode, which allows various bugs to be revealed and shows areas that remain untyped.

As there are many things to fix, I've added an optional step to the CI workflow.

Refs #398, #422
thewilkybarkid added a commit that referenced this issue Nov 4, 2021
As typechecking is separate from running code, ts-node needs to have it explicitly disabled. We've only noticed this problem once TypeScript's strict mode was enabled, as there are currently type problems.

As an aside, this will also be fractionally quicker.

Refs #398, #422, 163bd96
thewilkybarkid added a commit that referenced this issue Nov 4, 2021
thewilkybarkid added a commit that referenced this issue Nov 8, 2021
This change removes the untyped getActivePersona function, which doesn't do anything useful.

Refs #398, #422
thewilkybarkid added a commit that referenced this issue Nov 24, 2021
Rather than misusing a private decorator-specific API, this change uses the ORM's metadata storage instead.

A slight issue here is that accessing the entity manager from a repository is technically not a public API, but the code doing so isn't (yet) TypeScript and needs a lot of work anyway.

Refs #398, #399
thewilkybarkid added a commit that referenced this issue Dec 17, 2021
The OpenAPI generator script stubs dependencies that aren't run; this change avoids future typing problems by using an 'any' type.

Using 'any' is usually not advised, but it's more pragmatic given the alternatives.

Refs #398, d86fcc5
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant