5monkeys/django-bananas.js

Refactor to TypeScript

Opened this issue · 3 comments

Refactor to TypeScript

I think this would be really nice. However, it would probably mean we refactor everything to use modern React (17-18) patterns like hooks and lazy imports. Quite a big investment time-wise since we are at a pretty stable point in Bananas as of now. A complete refactor would surely introduce a lot of bugs.

A slightly less time demanding option would be to have all new features be written in TypeScript. We would probably need to update/modify our Webpack setup for it to handle .ts/tsx files but that would probably be pretty quick and easy.

The quickest option to make Bananas more TS-friendly would be to make a PR to https://github.com/DefinitelyTyped/DefinitelyTyped and have them publish @types/django-bananas.js to npm. The typings of everything that Bananas exposes would in that case be accessible for anyone using TS through that package. The downside is of course that the code base itself wouldn't be TS at all 👎

As @hbystrom91 suggested I have made some very loose typings in DefinitelyTyped/DefinitelyTyped#60784 for DefinatelyTyped which is waiting for review currently....

This issue is partly solved now by the @types/django-bananas npm package. While it works, it is somewhat untyped still (lots of any and certain external types were not linked due to some issues with compatibility between typescript/javascript module resolver types). I tried to match the code and the previously written types in mestergruppen admin as best I could but it is very possible I missed some weird JS properties which were not directly mentioned in code (for example in swagger-client which is untyped and extended by our APIClient) .

Ideally I would like to refactor everything and gradually move over to typescript fully (especially re-write the ApiClient) but that is way out of scope so for now the DefinitelyTyped types will do.