首页 > 解决方案 > 向本机 ios 组件提供道具时出现“不必要”的 TS 问题

问题描述

我使用 Swift 创建了一个名为 CounterView 的本机模块,当我这样使用它时:

<CounterView style={{flex: 1}} />

我收到了这个讨厌的警告!但问题是,一切正常。如果我删除样式道具,错误就会消失,但如果没有 {flex: 1},则不会呈现任何内容。所以我试图将它包装在一个视图中,但随后它相对于整个屏幕而不是包装器呈现。我怎样才能摆脱这个错误?我做错了什么使我的组件“只读”吗?

Type '{ style: { flex: number; }; }' is not assignable to type 'IntrinsicAttributes & IntrinsicClassAttributes<Component<unknown, {}, any> & Readonly<NativeMethods>> & Readonly<...> & Readonly<...>'.
  Property 'style' does not exist on type 'IntrinsicAttributes & IntrinsicClassAttributes<Component<unknown, {}, any> & Readonly<NativeMethods>> & Readonly<...> & Readonly<...>'.

如果我这样做,我可以绕过这个问题:

<View style={{flex: 1}}>
  <View style={{flex: 1}} />
  <View style={{flex: 1}}>
    <CounterView />
  </View>
</View>

这会处理将被另一个 flex:1 容器占用的另一半屏幕,但这看起来很傻。

标签: iosswifttypescriptreact-native

解决方案


推荐阅读