frontpage.
newsnewestaskshowjobs

Open Source @Github

fp.

Open in hackernews

Parse, Don't Validate – In a Language That Doesn't Want You To

https://cekrem.github.io/posts/parse-dont-validate-typescript/
33•fagnerbrack•1h ago

Comments

robertlagrant•1h ago
This feels right, and I also have never done it (or had the guts to get others to do it).

The reason I've not is - say there's an optional field. Currently we call that null, probably, and check each time if it's there or not. I could instead make a type, like User and UserWithPhoneNumber. Should we be making types for each combination of present/absent fields? That can't be right.

The classic answer is to move the logic inside the domain object, or have a helper function outside the object, so you aren't constantly checking for field presence/absence, but are instead writing the logic once and calling some code.

I'm not sure in practice types can help with this. But I'd love to be proven wrong.

pillmillipedes•59m ago
if a user with/without phone number are equally valid states to be then types won't help you much. I think it's more about writing

  class User{phone: ?PhoneNumber}
over

  class User{phone: ?string}.
throwwwll•15m ago
To expand and give some notion of good taste:

It's more about writing

    struct User {phone: MaybePhoneNumber} // give or take, it's a monoid
over

    struct User {phone: Option<String>}
xx_ns•56m ago
I think this is a slightly different problem. The absence of an optional field, if that's a legal state, is meaningful every time you use the type, so you encode it on the field: `phone: ValidPhoneNumber | null`. When it's not null you're still guaranteed a valid phone number. When it is null, that's a legal state you have to handle and which is domain logic, not validation you forgot to do.

The combinatorial explosion you're picturing only shows up if you make a separate type per combination of present fields, but you don't need to. An independent optional field stays one `T | null`. You only reach for distinct types when fields are correlated and present together because they represent a state, and then it's a discriminated union on a status field, which is N states, not 2^N.

conartist6•43m ago
Don't forget to freeze the objects
hankbond•23m ago
As a new TypeScript user these are concepts that have greatly helped me simplify my code and improve reliability discrete of testing. Many LLMs guide in this direction if you loosely ask them, but having a concise post like this with the what and the why is fantastic as reference material. The suggestion to use Separation and a Linter rule is something I'm going to immediately look into for my current project. Great post!
lumpysnake•10m ago
We should make authors disclose how much AI was used to write an article. This reeks of Opus 4.8.
ramses0•10m ago
Meta: in addition to upvotes and downvotes, we almost need a slop/not-slop slider.

This one barely scrapes by at what feels like 30-40% "slop": "honestly", "the one thing", etc...

...but I did learn something about "Brand" types, and have personally tried to do more of "parse don't validate" in my own code.

Recently I did this similar trick for `exec( ValidExecutable(...) )` [python], where it required tagging/washing through a private function/variable to "get" the private bit.

All the scanners tend to light up when they see "exec" at all (eg: `exec( "pandoc" )` for PDF generation), but I needed to hard code a few "expected" pandoc locations so the imaginary hackers couldn't shadow "pandoc" on a path location they controlled.

ivolimmen•4m ago
One of the pillars of Domain Driven Design. I love working on a pure DDD application but I do not often convince my team (I am a constant) that this is the best way ...

European digital ID wallets are a gift to Google and Apple

https://waag.org/en/article/european-digital-id-wallets-are-gift-google-and-apple/
267•donohoe•2h ago•114 comments

The US ambassador had Belgian police stop our reporting

https://europeancorrespondent.com/en/r/the-us-ambassador-had-belgian-police-stop-our-reporting
122•robtherobber•2h ago•28 comments

Building a custom octocopter from scratch with no prior hardware experience

https://karolina.mgdubiel.com/drone/
99•noleary•2d ago•25 comments

Parse, Don't Validate – In a Language That Doesn't Want You To

https://cekrem.github.io/posts/parse-dont-validate-typescript/
33•fagnerbrack•1h ago•10 comments

Open Source Low Tech

https://opensourcelowtech.org/
353•grep_it•4d ago•65 comments

Sony erases digital content from libraries; reminded we don't own what we buy

https://arstechnica.com/gadgets/2026/06/sony-erases-digital-content-from-libraries-were-reminded-...
98•pseudolus•1h ago•38 comments

Qwen 3.6 27B is the sweet spot for local development

https://quesma.com/blog/qwen-36-is-awesome/
987•stared•19h ago•643 comments

Exercise intensity influences body composition in healthy older adults

https://www.maturitas.org/article/S0378-5122(25)00571-7/fulltext
51•bookofjoe•2h ago•49 comments

Antares Achieves Criticality of Mark-0 Reactor

https://antaresindustries.com/updates/antares-achieves-criticality
40•clarionbell•3h ago•28 comments

.self: A new top-level domain designed to support self-hosting

https://hccf.onmy.cloud/2026/06/21/reclaiming-our-digital-selves-hccfs-vision-for-a-human-centere...
554•HumanCCF•16h ago•321 comments

Free the Icons

https://weblog.rogueamoeba.com/2026/06/26/free-the-icons/
522•zdw•2d ago•172 comments

The operating cost starts after the demo

https://twoheads.net/the-promise-is-unattended-work/
37•hellokfk•4d ago•23 comments

Memory Safe Context Switching

https://fil-c.org/context_switches
154•modeless•12h ago•25 comments

LongCat-2.0, a large-scale MoE model with 1.6T total and 48B Active

https://longcat.chat/blog/longcat-2.0/
182•benjiro29•12h ago•47 comments

Rocketlab acquires Iridium

https://investors.rocketlabcorp.com/news-releases/news-release-details/rocket-lab-acquire-iridium...
424•everfrustrated•22h ago•279 comments

Linux for the Sega MegaDrive

https://github.com/LinuxMD/linuxmd
147•HardwareLust•21h ago•18 comments

Old Computer Challenge

http://occ.sdf.org/
82•wrxd•2d ago•32 comments

Exploring PDP-1 Lisp (1960)

https://obsolescence.dev/pdp1-lisp-introduction.html
88•ozymandiax•11h ago•22 comments

Ornith-1.0: self-improving open-source models for agentic coding

https://github.com/deepreinforce-ai/Ornith-1
222•danboarder•19h ago•41 comments

One million passports leaked online

https://www.theverge.com/tech/947157/passports-data-breach-cannabis-club-systems-nefos-puffpal
315•jruohonen•2d ago•191 comments

All Logic, No Bite

https://lcamtuf.substack.com/p/all-logic-no-bite
10•surprisetalk•3d ago•0 comments

Why Problem Statements Aren't Enough

https://letters.unchartedpathbreakthroughs.com/posts/why-problem-statements-arent-enough
7•mooreds•4d ago•3 comments

How to corrupt an SQLite database file

https://www.sqlite.org/howtocorrupt.html
102•tosh•3d ago•20 comments

US Supreme Court rules geofence warrants require constitutional protections

https://www.theguardian.com/us-news/2026/jun/29/supreme-court-geofence-warrants-case-decision
546•cdrnsf•20h ago•251 comments

30-year sentence for transporting zines is a five-alarm fire for free speech

https://theintercept.com/2026/06/26/daniel-sanchez-estrada-zines-prairieland-free-speech/
640•xrd•1d ago•376 comments

Zig – SPIR-V Backend Progress

https://ziglang.org/devlog/2026/#2026-06-26
81•Retro_Dev•4d ago•44 comments

Apple Neural Engine: Architecture, Programming, and Performance

https://arxiv.org/abs/2606.22283
193•Jimmc414•2d ago•25 comments

Dark Sky Lighting

https://www.savingourstars.org/darkskylighting#whatisdarkskylighting
223•alexandrehtrb•4d ago•40 comments

WATaBoy: JIT-Ing Game Boy Instructions to WASM Beats a Native Interpreter

https://humphri.es/blog/WATaBoy/
218•energeticbark•21h ago•34 comments

What happens when you run a CUDA kernel?

https://fergusfinn.com/blog/what-happens-when-you-run-a-gpu-kernel/
268•mezark•23h ago•31 comments