Validation with Type Guards and Mapped Types

Slightly enhanced version of the code is now on NPM and GitHub.

Having spent a significant portion of my programming career using dynamic languages I understand the value of rapid prototyping and feedback that they provide. I’ve also seen enough dynamic code to know that most dynamic codebases are full of brittle validation logic that our brethren from the statically typed camp don’t have to deal with. Well, that’s not entirely true. They still have to deal with it but I think they have an easier time because the compiler can help them. There are many solutions to dealing with this problem in the dynamic camp in the form of libraries and DSLs but today I’m going to present a solution that uses nothing but TypeScript’s built-in capabilities to help us build validators for POJOs (plain old JavaScript objects). Continue reading

Incremental Compilation with Symlinks

So it turns out that TypeScript doesn’t really have incremental compilation. This means if I rely on some 3rd party modules then recompiling anything that depends on that 3rd party module will transitively recompile everything. I understand that TypeScript is not a build system so delegating those responsibilities to one is a sensible design decision. The trouble with build systems is they can get pretty hairy pretty fast and ideally I want to avoid the overhead of one. Fortunately we can avoid the hairy parts of a build system by using a few symlinks and declaration files. Continue reading

Constraint Solving with Picat

I’ve been playing around with a few multi-paradigm programming languages. The most recent one is called Picat. It’s a hybrid language that is a mix of logic, imperative, actor, and functional paradigms with built-in constraint solvers and planners. That’s a lot to take in so whenever I’m faced with a language with roots in the logic paradigm the first thing I try to do is solve “SEND + MORE = MONEY” cryptarithmetic puzzle. It’s a small and manageable problem and there are at least two ways to solve it so it allows one to exercise several features of the logic and constraint paradigms. Continue reading