javascript 没有与此调用匹配的重载,重载1/2,'(props:视图属性|只读< ViewProps>):View“,出现以下错误,(React Native)

pftdvrlh  于 2023-01-01  发布在  Java
关注(0)|答案(1)|浏览(488)
(alias) class View
import View
No overload matches this call.
  Overload 1 of 2, '(props: ViewProps | Readonly<ViewProps>): View', gave the following error.
    Type '{ children: Element[]; style: { flexDirection: "row"; alignItems: "center"; marginTop: number; }; }' is not assignable to type 'IntrinsicAttributes & IntrinsicClassAttributes<View> & Readonly<ViewProps>'.
      Property 'children' does not exist on type 'IntrinsicAttributes & IntrinsicClassAttributes<View> & Readonly<ViewProps>'.
  Overload 2 of 2, '(props: ViewProps, context: any): View', gave the following error.
    Type '{ children: Element[]; style: { flexDirection: "row"; alignItems: "center"; marginTop: number; }; }' is not assignable to type 'IntrinsicAttributes & IntrinsicClassAttributes<View> & Readonly<ViewProps>'.
      Property 'children' does not exist on type 'IntrinsicAttributes & IntrinsicClassAttributes<View> & Readonly<ViewProps>'.ts(2769)

我不知道为什么我得到这个错误。甚至审查了其他堆栈溢出类似的问题。问题没有解决。
我使用的是从react native导入的样式表。
代码:-

<View style={styles.createPostContainer}>
        <View style={styles.addPostButtonContainer}>
          <TouchableOpacity
            data-elementId="button_next"
            onPress={this.discordChanges}
          >
            <Image
              data-elementId="image_Back"
              style={[DS ? styles.image_BackImage_5inch : styles.image_BackImage]}
              source={back}
            />
          </TouchableOpacity>
        </View>
        <Text
          data-elementId="textlabel_Payments"
          style={[DS ? styles.textlabel_PaymentsText_5inch : styles.textlabel_PaymentsText]}
        >
          Create Post
        </Text>
      </View>

我的项目信息:-

npx react-native info
info Fetching system and libraries information...
System:
    OS: macOS 13.0.1
    CPU: (8) arm64 Apple M1
    Memory: 199.59 MB / 16.00 GB
    Shell: 5.8.1 - /bin/zsh
  Binaries:
    Node: 18.9.1 - /opt/homebrew/bin/node
    Yarn: 1.22.18 - /opt/homebrew/bin/yarn
    npm: 8.19.1 - /opt/homebrew/bin/npm
    Watchman: 2022.09.19.00 - /opt/homebrew/bin/watchman
  SDKs:
    iOS SDK:
      Platforms: DriverKit 21.4, iOS 16.0, macOS 12.3, tvOS 16.0, watchOS 9.0
  IDEs:
    Android Studio: 2021.3 AI-213.7172.25.2113.9014738
    Xcode: 14.0/14A309 - /usr/bin/xcodebuild
  npmPackages:
    @react-native-community/cli: ^9.1.1 => 9.1.3 
    react-native: file:./packages/blocks/core/node_modules/react-native => 0.61.3 
  npmGlobalPackages:
    react-native: 0.70.1

我试着减少 typescript 版本。不知道为什么我这样做,只是尝试了一下。希望任何人都能帮助我。:)

nle07wnf

nle07wnf1#

已在yarn.lock文件中添加此代码,然后删除所有节点模块并重新安装所有依赖项。
“@类型/React@":版本“17.0.38”解决了完整性https://registry.yarnpkg.com/@types/react/-/react-17.0.38.tgz#f24249fefd89357d5fa71f739a686b8d7c7202bdsha 512-SI 92 X1 IA + FMnP 3qM 5 m4 QReluXzhcmovhZnLNm 3 pyeQlooi 02 qI 7sLiepEYqT 678 uNiyc 25 XfCqxREFpy 3 W7 YhQ ==依赖项:“@类型/属性类型”“”“@类型/计划程序”“*”cs类型“^3.0.2”
这个解决方案是我的同事推荐给我的。另外,请确保删除现有的@types/react@,然后用它来替换我上面的解决方案。请让我知道伙计们,如果解决方案的作品或不适合你。谢谢你的所有帮助。

相关问题