【问题标题】:React Native Sortable List JSX element class does not support attributesReact Native Sortable List JSX 元素类不支持属性
【发布时间】:2021-03-04 15:43:00
【问题描述】:

我正在使用这个库:https://github.com/gitim/react-native-sortable-list ("react-native-sortable-list": "0.0.24") 没有类型定义,所以我使用: “@types/react-native-sortable-list”:“^0.0.9”。

我在 tsx 文件(打字稿)中定义了以下组件:

import SortableList from 'react-native-sortable-list'
import ....// others

interface Props {
    tasks: ITask[]
}
export default function TasksList(props: Props) {

    return (
        <SortableList
            data={props.tasks}
            renderRow={({ active, data, disabled, index, key }) => {
                return (
                    <View key={key}>
                        <Text>{data.name}</Text>
                    </View>
                )
            }}
        />
     )
}

代码可以正常工作(列表渲染得很好),但我得到一个 Typescript 错误:

JSX 元素类不支持属性,因为它没有“props”属性。ts(2607) 'SortableList' 不能用作 JSX 组件。 它的实例类型 'SortableList' 不是有效的 JSX 元素。 类型 'SortableList' 缺少类型 'ElementClass' 的以下属性:render、context、setState、forceUpdate 和 3 more.ts(2786)

我不知道如何使错误消失。有什么想法吗?

【问题讨论】:

    标签: react-native


    【解决方案1】:

    我发现 Visual Studio Code 有 Typescript 版本 4.1.5。一旦我将其更改为 3.9.9,错误消息就消失了!

    【讨论】:

      猜你喜欢
      • 2018-10-04
      • 2021-11-12
      • 2017-08-18
      • 2021-10-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-05-31
      • 2020-07-05
      相关资源
      最近更新 更多