DEV Community

Discussion on: Type-Safe Error Handling In TypeScript

Collapse
 
stealthmusic profile image
Jan Wedel

Would be great if typescript allows pattern matching, then you’ll do

with(result){
   Err(e) => console.log(“error!”);
   Ok(value) => console.log(value);
}
Enter fullscreen mode Exit fullscreen mode
Collapse
 
kip13 profile image
kip

Rust flavor here

Thread Thread
 
stealthmusic profile image
Jan Wedel

Yes, that's nice. There are a couple of functional languages that support it. E.g. Erlang where I first saw this in action.

Collapse
 
_gdelgado profile image
Gio

Maybe one day!

Thread Thread
 
stealthmusic profile image
Jan Wedel

Actually you can do something similar:

blog.logrocket.com/pattern-matchin...

It’s not as pretty as real pattern matching but it fits to this use car.

Collapse
 
impurist profile image
Steven Holloway