我正在与 react-scroll 。有一个道具类型别名,它看起来像这样:
export type ScrollElementProps<P> = P & { name: string; id?: string | undefined; };
我试图扩展道具类型,但我认为我是在倒退。我尝试过:
interface MyElementProps extends ScrollElementProps {...}
但它当然在告诉我: Generic type 'ScrollElementProps' requires 1 type argument(s)
Generic type 'ScrollElementProps' requires 1 type argument(s)
我如何写这篇文章,以便我的界面识别 ScrollElementProps 键入别名?
ScrollElementProps
TIA!
当然,我一发布问题就想出来了!
此类型别名是为预期道具接口/别名而构建的,因此它应该是这样的:
interface ScrollProps { myProps: string someMoreProps: boolean } export const Scroll = ({ myProps, someMoreProps, }: ScrollElementProps<ScrollProps>) => { ... }