繁体   English   中英

为 props 添加 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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM