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

WithQueryHOC type definition expects all props from parent component #1

Open
kevinydhan opened this issue Dec 17, 2020 · 0 comments
Open
Labels
bug Something isn't working

Comments

@kevinydhan
Copy link
Owner

kevinydhan commented Dec 17, 2020

In the following type definition for WithQuery:

import { FunctionComponent } from 'react'

type WithQuery = <Props = Record<string, never>>(
  Component: FunctionComponent<Props>,
  useQueryHook: () => Props
) => FunctionComponent<ReturnType<typeof useQueryHook>>

useQueryHook()'s return type should be one of the following:

  1. all of the component's props
  2. a subset of the component's props

In addition, the parameter for the WithQueryHOC component should also be one of the two cases:

  1. all of the component's props
  2. a subset of the component's props


Considering these two requirements, a possible type definition would be to use Partial<T> for both useQueryHook()'s return value and the parameter for the WithQueryHOC component:

import { FunctionComponent } from 'react'

type WithQuery = <Props = Record<string, never>>(
  Component: FunctionComponent<Props>,
  useQueryHook: () => Partial<Props>
) => FunctionComponent<ReturnType<typeof useQueryHook>>

However, this poses the problem where calling React.createElement() with partial props will trigger a TypeScript warning.

@kevinydhan kevinydhan added the bug Something isn't working label Dec 17, 2020
@kevinydhan kevinydhan changed the title WithQueryHOC type definition expects all props from parent component WithQueryHOC type definition expects all props from parent component Dec 17, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant