I have created a React component that takes a class of its child component. This component is responsible for providing the user ability to login via the OIDC protocol and if the user is logged in – rendering the child passing the user object as a prop (the child would use it in API calls).
This is how my component is declared:
type AuthProps = {
childClass: typeof React.Component;
}
type AuthState = {
user: Maybe<User>
}
class Auth extends React.Component<AuthProps, AuthState> {
}
Then I render my child element like:
<this.props.childClass user={this.state.user} />
This configuration works just fine. But what if I wanted more type safety? Namely if I want to ensure that childClass supports the user prop? I tried to type it like:
childClass: typeof ReactComponent<{user: Maybe<User>}>,
this, however is not even a proper syntax. Is it possible to narrow the type of childClass somehow?