I have a React component whose type is based on a runtime variable (isMock) and having difficulties with getting the TS declarations to work:
The component is either MockedProvider or ApolloProvider from @apollo/client which have two different props declaration.
const isMock: boolean = true // hardcoded for now...
const GraphQLProvider = isMock ? MockedProvider : ApolloProvider
const mockProps = { ... }
const realProps = { ... }
type ProviderType = typeof MockedProvider | typeof ApolloProvider
const GraphQLProvider: ProviderType = isMock ? MockedProvider : ApolloProvider
type ProviderProps = React.ComponentProps<typeof GraphQLProvider>
const graphQLParams: ProviderProps = isMock ? mockProps : realProps
return (
<GraphQLProvider {...graphQLParams}> // Error here...
...
</GraphQLProvider>
)
The above does not work. How would I correctly write declarations to allow for the condition isMock?
I didn't post the error since its quite verbose but basically it tells me that one or more props is missing even though it's not for the determined component.