I'm pretty new to TypeScript or even JavaScript for that matter. And I've been trying to wrap my head around an example from Microsoft on how to integrate AzureAD authentication in a react app. The example uses an HOC to provide authentication to a component. The declaration for the HOC looks like this:
function withAuthProvider<T extends React.Component<AuthComponentProps>>(
WrappedComponent: new (props: AuthComponentProps, context?: any) => T
): React.ComponentClass {...}
Most of it is more or less clear. What puzzles me is the type of WrappedComponent
. Specifically I don't understand what the new
keyword does in that context.
Can anyone help me out?
It's a constructor type. It means that when you invoke it with
new
, you can give it aprops
argument and an optionalcontext
argument, and it'll construct an instance of typeT
.Here's an example: