Re:Astro 1.0 – a web framework for building fast, content-fo...
by paldepind2 on Wednesday August 10, 2022 @02:10AM
(#32408307)
But TypeScript doesn’t have ADTs which you stated was a hard requirement. It has some other features that can achieve similar things though, so maybe that’s good enough?
[ Parent
| on HN ]
Re:Astro 1.0 – a web framework for building fast, content-fo...
by piaste on Wednesday August 10, 2022 @09:01AM
(#32411188)
Kinda nitpicky. Sure ADTs are a pattern in Typescript rather than a first-class entity, but they're an extremely well-supported pattern, exhaustiveness checking and all.
type ADT =
| { case : 'a', a : Number }
| { case : 'b', b : string }
function f (c : ADT) {
switch(c.case) {
case 'a' : return c.a
case 'b' : return Number.parseInt(c.b)
// case 'c' : return 0 // compile error
// case 'b' : return c.a // also compile error
}
}
Re:Astro 1.0 – a web framework for building fast, content-fo...
by mind-blight on Wednesday August 10, 2022 @04:21AM
(#32409170)
Discriminated unions aren't quite as nice, but they're pretty close.