Is there a Typescript Generic Type that will norma...
# typescript
w
Is there a Typescript Generic Type that will normalize promises out of Inputs/Outputs definitions?
Here is my usecase and what I’m doing to workaround my knowledge gap:
Copy code
type PlainIngressRule = Omit<networking.v1.IngressRule, 'http'> & {
  http: networking.v1.HTTPIngressRuleValue & {
    paths: (Omit<networking.v1.HTTPIngressPath, 'pathType' | 'backend'> & {
      pathType: string;
      backend: Omit<networking.v1.IngressBackend, 'service'> & {
        service: networking.v1.IngressServiceBackend;
      };
    })[];
  };
};

const createAndValidateIngressRule = (
  rule: PlainIngressRule
): PlainIngressRule => {
  if (!rule.host) {
    throw new Error(
      'Ingress rule must have a host. For example: *.<http://test.foobar.com|test.foobar.com> or <http://test.foobar.com|test.foobar.com>'
    );
  }
  if (!rule.http) {
    throw new Error('Ingress rule is missing HTTP configuration');
  }
  if (!rule.http.paths) {
    throw new Error('Ingress rule is missing HTTP configuration');
  }

  for (const path of rule.http.paths) {
    if (!path.pathType) {
      throw new Error(`Ingress rule path type is missing`);
    }
    if (!['ImplementationSpecific'].includes(path.pathType)) {
      throw new Error(`Ingress rule path type is not valid: ${path.pathType}`);
    }
    if (!path.backend) {
      throw new Error(`Ingress rule path is missing backend`);
    }
    if (!path.backend.service) {
      throw new Error(`Ingress rule path is missing backend service`);
    }
    if (!path.backend.service.name) {
      throw new Error(`Ingress rule path is missing backend service name`);
    }
    if (!path.backend.service.port) {
      throw new Error(`Ingress rule path is missing backend service port`);
    }
  }
  return rule;
};
I should look at what
all()
is doing
Unwrap
Got it
Thank you!
Unwrap
was what I was looking for those coming across this thread later.
🙂 1