传播类型只能从对象类型创建

Spread types may only be created from object types

我有一个使用 ts 的简单 react-native 组件,它指定了自己的样式,但是我也想从组件树上方(即我正在使用此组件的地方)传递我可能使用的任何样式

class RatioImage extends React.Component<Props> {
  render() {
    const { width, ratio, style, ...props } = this.props;
    return (
      <Image
        {...props}
        style={{
          width: deviceWidth * (width / 100),
          height: deviceWidth * (width / 100) * ratio,
          ...style
        }}
      />
    );
  }
}

我目前在我的 ...style 上收到以下错误,不知道为什么,因为它应该是一个对象?

[ts] Spread types may only be created from object types.
const style: false | ImageStyle | (number & {
    __registeredStyleBrand: ImageStyle;
}) | RecursiveArray<false | ImageStyle | (number & {
    __registeredStyleBrand: ImageStyle;
}) | null | undefined> | null | undefined

您需要使用数组语法在 React Native 中提供多种样式

<Image style={[{ width: x, height; y}, style]} />

the docs for more info