5 ms·
Not OP. Looks interesting, but I'd bet that typescript's type system would enforce constraints a lot better
by Matheus28 4y ago
Not OP. Looks interesting, but I'd bet that typescript's type system would enforce constraints a lot better
- whacked_new 4y agoin my experience, for things like static configs, jsonnet has been superior to TS for constraints, if you pair the configs with a json schema (also generated from jsonnet, of course). TS's types are easier to use at write-time, but json schema includes a lot of batteries that save a lot of time when you need them, but become annoying in TS, like patternProperties in dictionaries, length constraints in keys. Of course, there are situations like key1 XOR key2 where you will need custom logic one way or another, but given json schema's evolution over the years, I think it's pretty solid. An added benefit is that if you stay in json schemas, you're almost guaranteed a validator exists in $other_language, it _almost_ feels like a first-class construct everywhere.
- Matheus28 4y agoThat's a valid point. I think that TS might also lack constraints for object keys and values (like matching them against a regex). After thinking for a while, I think that json schema might be the best approach to it (possibly generated from jsonnet if complicated enough).