Navigate Select ESC Close

The most important function in my codebase

2025-03-20 Science & Technology
153.5k
4.8k
559
Theo - t3․gg
Theo - t3․gg
539.0k subscribers

Unlock all features

FREE: Get instant access to 10 AI summaries, chats, or transcripts per day.

Description

Error handling in TypeScript is bad. Try catch is NOT a good pattern. Go got a lot wrong, but returning errors as values was absolutely right. Thank you CodeRabbit for sponsoring! Check them out at: https://soydev.link/coderabbit SOURCES https://gist.github.com/t3dotgg/a486c4ae66d32bf17c09c73609dacc5b https://github.com/supermacro/neverthrow https://effect.website/ https://ethanniser.dev/blog/the-truth-about-effect/ Try T3 Chat? https://soydev.link/chat Want to sponsor a video? Learn more here: https://soydev.link/sponsor-me Check out my Twitch, Twitter, Discord more at https://t3.gg S/O Ph4se0n3 for the awesome edit 🙏

Top Comments (10)

@brennan123 2025-03-20

Go developer: This is how Go does it. Rust developer: No, Go doesn't do it right, this is the Result pattern from Rust. You need strong types for this to work. Haskell developer: No, Rust doesn't do it right. This is just the Either pattern. Haskell's do notation allows you to "bind" functions together much cleaner. Computer scientist: No, Haskell stole that from category theory—it's just a monad and Kleisli composition in disguise. Mathematician: No, you're overcomplicating this, monads are just monoids in the category of endofunctors.

355 7 replies
@faisalmahmood6467 2025-03-20

The neverthrow paradigm API-wise looks very similar to how Rust does it

37 1 replies
@sebastianlumina 2025-03-20

I think it’s super cool that you are not afraid to show that you’re still learning and there’s loads of stuff you don’t know that you would like to learn.

136 2 replies
@Scott_Stone 2025-03-20

We tried similar things to what effect is doing in our c# codebase. Honestly, it slows down productivity to a halt. Neverthrow or whatever the golang has is the only way to stay productive. We went back to something that resembles Neverthrow in our app and it's been a bliss since.

20 1 replies
@solinovo 2025-03-20

This is re-discovering FP the long route (still valuable though). I know theo is aware of effect library though, you are just a couple of steps away from re-discovering unary functions and then composability is unlocked with pipes. JK He mentioned effect later BASED

101
@youreyesarebleeding1368 2025-08-13

This channel is such a good resource, I didn't learn anything about web development or real hands on full stack stuff in university, but this year i've gone from not knowing any JS to writing my own full stack apps with Next.js and TypeScript and I've been learning new design patterns every day

1
@WillDelish 2025-03-21

I was building a cli app and thought to myself how much I loved the way rust has result and started using that pattern, which is very much like this! I like the idea of just making it its own function

2
@NikoE-l4u 2025-03-20

So you're advocating to Go-Style error handling :D

275 15 replies
@terminalcalm 2025-03-20

Helpful as always. And I like the way you segue into the ads each time. Shows thought.

0
@alejandroechavarria539 2025-03-21

This is the array version of the tryCatch function which I prefer and is more aligned with the safe assignment operator proposal: type Success<T> = [null, T]; type Failure<E> = [E, null]; type Result<T, E = Error> = Success<T> | Failure<E>; export async function tryCatch<T, E = Error>( promise: Promise<T>, ): Promise<Result<T, E>> { try { const data = await promise; return [null, data]; } catch (error) { return [error as E, null]; } }

1

Unlock the Data Inside
Turn Videos into Knowledge

  • Get FREE 10/day: transcripts, summaries, chats
  • Chat with videos, export text & PDF
  • $1 free API credit for RAG, chatbots & research

Free forever plan • All features unlocked

App screenshot