我正在使用react-scroll。有一個 props 型別別名,如下所示:
export type ScrollElementProps<P> = P & {
name: string;
id?: string | undefined;
};
我正在嘗試擴展道具型別,但我認為我正在倒退。我試過:
interface MyElementProps extends ScrollElementProps {...}
但它當然是在告訴我:Generic type 'ScrollElementProps' requires 1 type argument(s)
我該如何撰寫,以便我的界面識別ScrollElementProps型別別名所期望的道具?
蒂亞!
uj5u.com熱心網友回復:
當然,我一發布問題就想通了!
這種型別的別名是為了期望一個 props 介面/別名而構建的,所以它應該是這樣的:
interface ScrollProps {
myProps: string
someMoreProps: boolean
}
export const Scroll = ({
myProps,
someMoreProps,
}: ScrollElementProps<ScrollProps>) => {
...
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/qiye/460214.html
