How to strictly type a component props which include both the inner component to render and the inner component props?

Viewed 62

Here is what I want in the end, a wrapper component that renders passed in the final component only when data is fetched and validated successfully

<Wrapper
  url="/foo"
  as={FooComponent}
  validate={fooResponse => fooResponse != null}
  fooPropsA={1}
  fooPropsB={2}
/>

Here is my latest attempt https://tsplay.dev/3NDZOW

In brief, the requirements are following:

  1. inner component must have value prop to accept fetched value on a real render
  2. validate function argument should be inferred from inner component (prop) types
  3. wrapper component should accept all props of inner component, except value

Is it possible?

Note: there are similar questions which either says it's not possible or does slightly different job, but I failed to apply them to my case, thus not sure if it's even possible

1. Similar logic component https://stackoverflow.com/questions/51762529/use-props-to-pass-another-componentprops-to-be-rendered-and-keep-type-safety

2. Regarding type inference https://stackoverflow.com/questions/56505560/could-be-instantiated-with-a-different-subtype-of-constraint-object-ts2322

0 Answers
Related