我正在使用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!
当然,我一发布问题就想出来了!
这种类型的别名是为了期望一个props接口/别名而构建的,所以它应该是这样的:
interface ScrollProps {
myProps: string
someMoreProps: boolean
}
export const Scroll = ({
myProps,
someMoreProps,
}: ScrollElementProps<ScrollProps>) => {
...
}