On the author’s point of a “debug build” with runtime type checking, there is ts-runtime-checks [0], which looks to do something similar! I don’t have any experience with it however, just seen it looking at typescript-runtime-type-benchmarks [1]. There’s a few other similar things there too<p>[0] <a href="https://github.com/GoogleFeud/ts-runtime-checks">https://github.com/GoogleFeud/ts-runtime-checks</a><p>[1] <a href="https://github.com/moltar/typescript-runtime-type-benchmarks">https://github.com/moltar/typescript-runtime-type-benchmarks</a>
Out of curiosity, how long is your experience with TypeScript? I feel like I have to ask.<p>>TypeScript does not modify this code when it compiles to JavaScript<p>TypeScript does not modify <i>any</i> code which is valid JavaScript. Your idea of adding some sort of "debug build" to TypeScript would never be performed by `tsc`, but perhaps by bundlers, etc.<p>You might want to look up libraries like zod, or even better, Effect: <a href="https://effect.website/" rel="nofollow">https://effect.website/</a>
I don't come from TS, but this seems like a good intro to zig from that sort of perspective. There's a whole lot of paradigms to relearn when you switch to something like Zig and this kind of content is useful.<p>I'll nitpick with one complaint though...<p><pre><code> const values = std.AutoHashMap(Point, u32);
defer values.deinit();
try values.put(Point{ .x = 0, .y = 0 }, 1);
// ~~~~~~^~~~ error: expected 3 argument(s), found 2
</code></pre>
> The mistake here isn't on that line, and it doesn't have to do with the number of arguments. Rather, it's that I forgot to call .init() on the hash map<p>Well...<p><pre><code> >>> class MyType():
... def test(self, a, b): return a + b;
...
>>> x = MyType
>>> x.test(1, 2)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: test() missing 1 required positional argument: 'b'
</code></pre>
How else do you want unbound functions to behave when you haven't constructed an instance of the type yet? (And FWIW, zls in vscode correctly annotates values as having type `type` for me)
I'm surprised that the list of Zig quirks doesn't include aliasing and functions parameters: the compiler can pass your parameter by value or by reference as it wants so your function behaviour can change in case of aliasing..<p>An implementation defined behaviour worse than C, that's surprising..<p>Ada has the same issue, I wonder if Ada users can tell us if this pitfall is an issue or not in practice.