TE
TechEcho
Home24h TopNewestBestAskShowJobs
GitHubTwitter
Home

TechEcho

A tech news platform built with Next.js, providing global tech news and discussions.

GitHubTwitter

Home

HomeNewestBestAskShowJobs

Resources

HackerNews APIOriginal HackerNewsNext.js

© 2025 TechEcho. All rights reserved.

What can TypeScript learn from Zig? What can Zig learn from TypeScript?

87 pointsby danvk10 months ago

5 comments

sebws10 months ago
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:&#x2F;&#x2F;github.com&#x2F;GoogleFeud&#x2F;ts-runtime-checks">https:&#x2F;&#x2F;github.com&#x2F;GoogleFeud&#x2F;ts-runtime-checks</a><p>[1] <a href="https:&#x2F;&#x2F;github.com&#x2F;moltar&#x2F;typescript-runtime-type-benchmarks">https:&#x2F;&#x2F;github.com&#x2F;moltar&#x2F;typescript-runtime-type-benchmarks</a>
评论 #40996066 未加载
评论 #40998786 未加载
jesus-was-here10 months ago
Out of curiosity, how long is your experience with TypeScript? I feel like I have to ask.<p>&gt;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 &quot;debug build&quot; 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:&#x2F;&#x2F;effect.website&#x2F;" rel="nofollow">https:&#x2F;&#x2F;effect.website&#x2F;</a>
评论 #40995924 未加载
评论 #40994832 未加载
评论 #40996043 未加载
cdcarter10 months ago
I don&#x27;t come from TS, but this seems like a good intro to zig from that sort of perspective. There&#x27;s a whole lot of paradigms to relearn when you switch to something like Zig and this kind of content is useful.<p>I&#x27;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); &#x2F;&#x2F; ~~~~~~^~~~ error: expected 3 argument(s), found 2 </code></pre> &gt; The mistake here isn&#x27;t on that line, and it doesn&#x27;t have to do with the number of arguments. Rather, it&#x27;s that I forgot to call .init() on the hash map<p>Well...<p><pre><code> &gt;&gt;&gt; class MyType(): ... def test(self, a, b): return a + b; ... &gt;&gt;&gt; x = MyType &gt;&gt;&gt; x.test(1, 2) Traceback (most recent call last): File &quot;&lt;stdin&gt;&quot;, line 1, in &lt;module&gt; TypeError: test() missing 1 required positional argument: &#x27;b&#x27; </code></pre> How else do you want unbound functions to behave when you haven&#x27;t constructed an instance of the type yet? (And FWIW, zls in vscode correctly annotates values as having type `type` for me)
评论 #40991940 未加载
评论 #40994605 未加载
评论 #40995977 未加载
renox10 months ago
I&#x27;m surprised that the list of Zig quirks doesn&#x27;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&#x27;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.
评论 #41017000 未加载
sakesun10 months ago
Another language that we can build type with its own language is Python. The problem is that there is no checker for that kind of type, however :)
评论 #40992076 未加载
评论 #40994779 未加载