The death of non-domain types (int, string)

3 views
Skip to first unread message

Mike Austin

unread,
Apr 28, 2026, 6:02:36 PM (2 days ago) Apr 28
to PiLuD
At my previous company I created a presentation about abuse of non-domain types (string vs EmailAddress, etc.). Now there's no excuse in TypeScript not to do it. It's just like "newtype" - all type-checking, no runtime.

type ItemId = string & { readonly __type: unique symbol };
type TypeId = string & { readonly __type: unique symbol };

type oneToNine = 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9;
type zeroToNine = 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9;

type YYYY = `19${zeroToNine}${zeroToNine}` | `20${zeroToNine}${zeroToNine}`;
type MM = `0${oneToNine}` | `1${0 | 1 | 2}`;
type DD = `${0}${oneToNine}` | `${1 | 2}${zeroToNine}` | `3${0 | 1}`;

type DateString = `${YYYY}-${MM}-${DD}`;

type Item = {
  id: ItemId,
  title: string,
  typeId: TypeId,
  ...
}


Paul Tarvydas

unread,
Apr 29, 2026, 4:18:01 AM (yesterday) Apr 29
to pi...@googlegroups.com
This reminds me that altscript describes a useful-looking set of specific low-level types https://altscript.com/.

pt



--
You received this message because you are subscribed to the Google Groups "PiLuD" group.
To unsubscribe from this group and stop receiving emails from it, send an email to pilud+un...@googlegroups.com.
To view this discussion visit https://groups.google.com/d/msgid/pilud/aca97d6e-ce98-4454-8e08-0f429234f674n%40googlegroups.com.

Mike Austin

unread,
Apr 29, 2026, 3:01:35 PM (19 hours ago) Apr 29
to PiLuD
Ahh yes, literal typed things like Date would be awesome. Stop this config file runtime error nonsense.

Now, the question is how far I go down the rabbit hole:

Regular boolean:

  flagged: boolean - Is the item visually flagged (highlighted)

It's own type:

  type Flagged = boolean & { readonly __type: unique symbol };

  let flagged: Flagged = true as Flagged;
  flagged = !flagged as Flagged;

It's very specific - there's no mixing up with any other booleans, but now any logic needs to be cast back to Flagged. If I saw this code, I might ask if this is really needed. So I think that's where I'll stop.

Raoul Duke

unread,
Apr 29, 2026, 3:50:26 PM (18 hours ago) Apr 29
to pi...@googlegroups.com
actually naked bools are very bad very quickly. 

but are less bad in things like objective-c method calling conventions. 


Paul Tarvydas

unread,
Apr 29, 2026, 4:55:18 PM (17 hours ago) Apr 29
to pi...@googlegroups.com

FYI, I look at this in a different way: when I was faced with unravelling someone else’s optimized textual logic, I drew a diagram. Parsing diagrams is so easy these days that I wrote a little diagram->code generator and pushed it to github. A code generator is just a helper - it doesn’t even need to be Turing complete. It took me less time to build it (several days, (could have been several hours disregarding all of the typos I make these days)) than to create a short video about it https://www.youtube.com/playlist?list=PLHh2_dCKBPjYhpvWSvJNJdrsZE8lNHza7. [When I made these videos, I was targeting an unknown language called “frish”. Later, I revamped the repo to generate Python and Javascript as well. The first video in the playlist is an overview. The rest of the videos show the PBP source code being refactored (maybe not required viewing the first time around)]


pt


On Apr 28, 2026, at 6:02 PM, Mike Austin <mike.aus...@gmail.com> wrote:

Reply all
Reply to author
Forward
0 new messages