Re:How to rewrite classes using closures in JavaScript
by w3news on Sunday October 22, 2023 @01:21PM
(#37977253)
Typescript wil not help, you can create the same mass.
What me helped is to write almost all code functional and not oop.
Every method had just 1 way data can in and out the method, no side effects.
Classes have a lot of flexibility that make things complex and increase bugs.
If you are strict in what to accept and what to produce, and start with the test, if you create mess, you can eat refactor to create clean code.
I can't tell from a glance from either before or after what the fields of the class are, let alone what sort of data goes in them. I suspect my IDE would have a struggle as well, and allow mistakes, at runtime, to either raise exceptions, or perform incorrect behavior.
I think maybe a cleaner approach in this domain may be TS interfaces + standalone functions that act on them.