我在用着import { SearchBar } from 'react-native-elements';
它有一个onChangeText类型为的函数onChangeText: () => any;
我这样做了onChangeText={(text: string) => console.log("text", text)},它给了我 ts 错误:
Type '(text: string) => void' is not assignable to type '((text: string) => void) & ((text: string) => void) & (() => any) & (() => any) & (() => any) & ((text: string) => void) & (() => any) & (() => any) & (() => any)'.
Type '(text: string) => void' is not assignable to type '() => any'
Run Code Online (Sandbox Code Playgroud)
为什么这样做以及正确的方法是什么?
根据这个问题,最新版本中的类型定义被破坏。在新版本出来之前,您可以通过以下方法来解决该问题。
01方式:降级到3.4.0
// npm
npm install react-native-elements@3.4.0
// yarn
yarn add react-native-elements@3.4.0
Run Code Online (Sandbox Code Playgroud)
或者
02方式:参考问题中建议的评论中的基础道具
// npm
npm install react-native-elements@3.4.0
// yarn
yarn add react-native-elements@3.4.0
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1498 次 |
| 最近记录: |