Getting the parameters of a generic function in TypeScript

Viewed 59

I'm dealing with a generic React functional component that doesn't export its prop interface:

interface ComponentProps<T> {
    test: T;
}

export function Component<T>(props: ComponentProps<T>): React.ReactElement;

I would like to build a component that extends that component:

interface MyComponentProps<T> extends ComponentProps<T> {
    another: string;
}

function MyComponent<T>({ another, ...props }: MyComponentProps<T>): React.ReactElement {
    return <Component {...props}/>;
}

The problem is that I need to get access to the ComponentProps interface, which is not exported. Normally I can do it like this:

type ComponentProps = Parameters<typeof Component>[0];

but in this case, I need to somehow specify the generic:

type ComponentProps<T> = Parameters<typeof Component<T>>[0]; // Error

Is there any way how I can get access to the generic interface?

0 Answers
Related