3 ms·
Is there another example than the one you provided? What I see in OutputExists/OutputNotExists is actually a Maybe/Option type. doSomething<Maybe<Output>>
by ljm 5y ago
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
- 015a 5y agoYeah 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.