score:1

Accepted answer

finally managed to solve the issue

interface wrappedcomponentprops<t> {
  data: t
}

interface wrappercomponentprops<t, k> {
  apolloresult: queryresult<t>;
  wrappedcomponent: react.componenttype<wrappedcomponentprops<t> & k>;
  componentprops: omit<k, keyof wrappedcomponentprops<t>>;
}

type componentprops<t, k> = react.propswithchildren<wrappercomponentprops<t, k>>;

export const apolloresultwrapper = <t extends object, k = {}>(props: componentprops<t, k>) => {
  const sandbox = usesandboxcontext();

  if (props.apolloresult.error) {
    sandbox.logger.error('stuff broke', props.apolloresult.error);

    return <errorcontent />
  }
  if (props.apolloresult.loading) {
    return <pagespinner />;
  }
  if (!props.apolloresult.data) {
    return <errorcontent />
  }

  return <props.wrappedcomponent
    children={props.children}
    data={props.apolloresult.data}
    {...props.componentprops as k}
  />;
}

score:0

if the error is about <t extends object> place try to change type casting <t extends object> to .... as t extends object

https://www.typescriptlang.org/docs/handbook/jsx.html#the-as-operator


Related Query

More Query from same tag