So, as announced, I started moving towards TypeScript. To be fair, for every line of TypeScript I write, I still spend an hour-and-a-half searching for alternatives that I might have missed out on, but I’m going there.
I was going through the TypeScript handbook, and one of the first things I stumbled across was something like this:
I got a rash the moment I noticed it. Not because of the type parameter. In fact, I added that myself. But because the validator really is just a single function. A single function to implement a particular strategy. If it’s just a singe function, then what’s the point of all the other boilerplate. Why add a method to a class?
You still get all the compile time enforcement you need: if you have a component expecting a
Validator<String> then you can pass in
validZip, but you won’t be able to pass in
(b: boolean) => true since that’s a