[英]Add type for onClick property which is in …props in React TypeScript
[英]Add Typescript type to props
我想知道如何聲明我的 function 聲明中的參數...props
的類型為BaseViewProps
,格式如下:
export interface BaseViewProps extends ScrollViewProps {
}
/**
* Underlying layout for all screens
*/
export function BaseView({ children, ...props }) {
return (
<SafeAreaView style={styles.mainContainer}>
<ScrollView
contentContainerStyle={styles.scrollContainer}
{...props}
>
<AppHeader/>
{children}
</ScrollView>
</SafeAreaView>
)
}
我嘗試過這樣的事情:
export function BaseView({ children, ...props} = { any, BaseViewProps})
但后來我得到一個錯誤'any' refers to a type but is used as a value here
。
嘗試:
export function BaseView({ children, ...props}: : { children: any, [key: string]: BaseViewProps })
=
用於默認值,而不是類型
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.