Comment

Comment by reggieband

I'm a big fan of the new operators.

One of my remaining gripes with Javascript/Typescript is the try/catch mess around await. It makes assignment of const a pain for async calls that may reject.

e.g.

    let result: SomeType;
    try {
        result = await funcThatReturnSomeType();
    } catch (err) {
        doSomethingWithErr(err);
    }

    // at this point result is `SomeType | undefined`
    
    if (result) {
        doSomething(result);
    }
I really want some kind of structures that allow me to make `result` constant. In some cases I've rolled my own Maybe/Either wrapper and then move the try/await/catch into a function but that is still a pain.

This is such a common pattern in my code ... I wish there was a more elegant way to deal with it.

parent reggieband 7 years ago

Discussion

Live from the official Hacker News API

A modern reader for Hacker News · SvelteKit + Skeleton