Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

Is there another example than the one you provided?

What I see in OutputExists/OutputNotExists is actually a Maybe/Option type.

    doSomething<Maybe<Output>>(someObj)
      .map(({ url }) => url)
      .getOr(null)

   // value could either be url or null


Yeah my example was really just an Option type.

A better example: think of Kubernetes API objects. In short, expressed as typescript interfaces:

    type KubeObject = Pod | Service;
    interface Pod { kind: "Pod", metadata: Metadata, spec: { containers: Container[] } };
    interface Service { kind: "Service", metadata: Metadata, spec: { selector: ServiceSelector } };

    const f = ({ kind, spec: { containers, selector } }: KubeObject) => {}
So, the ability to destructure both 'spec.containers' and 'spec.selector' given just a KubeObject, and have the compiler use control flow analysis on 'kind' to mark one as 'never' or 'undefined' when its destructured on a type where it doesn't make sense.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: