It’s a great article, but your approach seems dangerous to me because you don’t have to check the error at all because there’s no requirement to destructive both properties. See below:
const [todo] = await on<Todo>(somePromise())
I mean it’s a cool code sample you wrote, it’s just dangerous. Follow my dev.to channel and I’ll be showing how to use the Either/Optional pattern to accomplish the same things you’re lookig for but in a way that forces you to check the error first.
It would be possible to simply switch the return order as in [error, todo]. That way you would always return an error and checking whether something happened would be up to you. Another way would be to create an Optional generic object, something along the lines of java optionals or other language monads.
I will follow your channel and await on (🤭) your article!
It’s a great article, but your approach seems dangerous to me because you don’t have to check the error at all because there’s no requirement to destructive both properties. See below:
I mean it’s a cool code sample you wrote, it’s just dangerous. Follow my dev.to channel and I’ll be showing how to use the Either/Optional pattern to accomplish the same things you’re lookig for but in a way that forces you to check the error first.
It would be possible to simply switch the return order as in [error, todo]. That way you would always return an error and checking whether something happened would be up to you. Another way would be to create an Optional generic object, something along the lines of java optionals or other language monads.
I will follow your channel and await on (🤭) your article!
Haha I see what you did there 🤣