Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

calculate the async renderer's return type from createAsyncRenderer's arguments #40

Open
lemke-ethan opened this issue Apr 16, 2024 · 1 comment

Comments

@lemke-ethan
Copy link
Collaborator

the returned function, namely the async renderer, from createAsyncRenderer doesn't always have to be possibly null. it would be nice if the return type of the async renderer was determined by the arguments of createAsyncRenderer, such that if none of the arguments show the potential for a null return value then null should not be a possible return value for the async renderer.

@sam-mfb
Copy link
Member

sam-mfb commented Apr 16, 2024

maybe something like this:

declare function createAsyncRenderer<
  T extends OnCompletedSuccessfullyArgs = OnCompletedSuccessfullyWithoutArgs
>(
  args: CreateAsyncRendererArgs<T>
): <TSuccess extends OnCompletedSuccessfully<T>, TError extends JSX.Element | React.FC<{errorMEssage?:string}> | undefined = undefined>(
  onCompletedSuccessfully: TSuccess,
  optionalArgs?: {
    onCompletedWithError?: TError
    onLoading?: JSX.Element | (() => JSX.Element)
    onInit?: JSX.Element | (() => JSX.Element)
  }
) => TSuccess extends JSX.Element | (()=>JSX.Element) ? TError extends JSX.Element | (()=>JSX.Element) | undefined ? ReactElement<any,any> : ReactElement<any, any> | null : ReactElement<any, any> | null

Here's a playground showing it working for some cases; not fully tested.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants