reactjstypescriptgenericsreact-scroll

interface X extends ScrollElementProps<P> = P & {}


I'm working with react-scroll. There is a props type alias which looks like this:

export type ScrollElementProps<P> = P & {
    name: string;
    id?: string | undefined;
};

I'm trying to extend the prop type, but I think I'm doing it backwards. I tried:

interface MyElementProps extends ScrollElementProps {...}

but of course it's telling me: Generic type 'ScrollElementProps' requires 1 type argument(s)

How do I write this so that my interface recognizes the props expected by the ScrollElementProps type alias?

TIA!


Solution

  • Of course I figured it out as soon as I posted the question!

    This type alias was built to expect a props interface/alias, so this is how it should look:

    interface ScrollProps {
      myProps: string
      someMoreProps: boolean
    }
    
    export const Scroll = ({
    
      myProps,
      someMoreProps,
    
    }: ScrollElementProps<ScrollProps>) => {
       ...
    }