4 ms·
TypeScript is limiting for describing schema in my experience. Try requiring an array of certain length, for example. Also, it’s Turing-complete, so you are en
by strogonoff 5y ago
TypeScript is limiting for describing schema in my experience. Try requiring an array of certain length, for example.
Also, it’s Turing-complete, so you are enabling future developers or users to shoot themselves in the foot and write something that does not halt already at configuration stage.
To me the perfect language for configuration seems to be Dhall, but it doesn’t seem to have gained any traction.
- throwaway894345 5y agoDhall is too unfamiliar for most developers, IMO. Developers don’t want to have to grok an entirely new syntax just for config. I’m personally surprised no one has added type annotations to Starlark yet.
- strogonoff 5y agoEverything is unfamiliar, until one adopts it.
- deleted 5y ago[deleted]
- throwaway894345 5y agoI didn't think it needed to be explained, but not all things are equally unfamiliar nor equally easily adopted.
- mattw1810 5y agoThe Rust implementation has it as an experimental extension (https://github.com/facebookexperimental/starlark-rust/blob/main/docs/types.md https://github.com/facebookexperimental/starlark-rust/blob/m...)
- throwaway894345 5y agoOooh, very cool! I'll check it out and maybe port to Go.
- ahuth 5y agoDepending on what you're looking to do, you can use a tuple type to get an array of a certain length. [number, number, number]
- strogonoff 5y agoI meant length that depends on another type, not length known beforehand (e.g., if N widgets are defined somewhere, [up to] N elements can exist somewhere else, or configuration should not compile). Naturally, this had to involve generics (similar to [0], except I don’t recall why but the `length` property workaround didn’t work or didn’t provide sufficient type safety in my use case). Eventually, after reading workarounds in a related issue[1], I gave up. TypeScript’s type system is great for its intended use, but when applied to expressing schema constraints it quickly falls short and runtime code execution is required to validate a given structure with all the corresponding drawbacks. [0] https://stackoverflow.com/q/56034226/247441 https://stackoverflow.com/q/56034226/247441 [1] https://github.com/microsoft/TypeScript/issues/26223 https://github.com/microsoft/TypeScript/issues/26223
- jonny_eh 5y ago> not length known beforehand Is that a feature of other languages?
- strogonoff 5y agoHaven’t had much exposure to other statically typed languages recently, so can’t say off the top of my head. Intuitively it looks like something modern generics should allow easily though, doesn’t it? As to Dhall, for example, I could validate such a constraint (and more) using a function I can be reasonably sure is safe and won’t halt (i.e. without all the drawbacks of TS and other general-purpose languages).