代码之家  ›  专栏  ›  技术社区  ›  Kraken

接口X扩展了ScrollElementProps<P>=P&{}

  •  0
  • Kraken  · 技术社区  · 4 年前

    我正在与 react-scroll 。有一个道具类型别名,它看起来像这样:

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

    我试图扩展道具类型,但我认为我是在倒退。我尝试过:

    interface MyElementProps extends ScrollElementProps {...}
    

    但它当然在告诉我: Generic type 'ScrollElementProps' requires 1 type argument(s)

    我如何写这篇文章,以便我的界面识别 ScrollElementProps 键入别名?

    TIA!

    1 回复  |  直到 4 年前
        1
  •  0
  •   Kraken    4 年前

    当然,我一发布问题就想出来了!

    此类型别名是为预期道具接口/别名而构建的,因此它应该是这样的:

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