typescript - React Native 中的 ReturnKeyType 数据类型

标签 typescript react-native

在我的 react native 应用程序中,我使用 typescript 。当我将 returnKeyType 作为 prop 传递时,我必须设置 returnKeyType 的类型。

<TextInput
 editable={editable}
 returnKeyType={returnKeyType}
 maxLength={maxLength}
/>

我的界面是这样的。

interface IProps extends Props<IProps> {
  editable?: boolean;
  maxLength?: number;
  returnKeyType: string;
}

当我将 returnKeyType 设置为字符串时,它会给出这样的错误。

"Type 'string' is not assignable to type '"none" | "done" | "search" | "default" | "go" | "next" | "send" | "previous" | "google" | "join" | "route" | "yahoo" | "emergency-call" | undefined'.ts(2322)
index.d.ts(1438, 5): The expected type comes from property 'returnKeyType' which is declared here on type 'IntrinsicAttributes & IntrinsicClassAttributes<TextInput> & Readonly<TextInputProps> & Readonly<{ children?: ReactNode}>"

如何在这里设置类型?

最佳答案

returnKeyType 是一个枚举,因此您应该能够执行以下操作:

interface IProps extends Props<IProps> {
  editable?: boolean;
  maxLength?: number;
  returnKeyType: "none" | "done" | "search" | "default" | "go" | "next" | "send" | "previous" | "google" | "join" | "route" | "yahoo" | "emergency-call";
}

关于typescript - React Native 中的 ReturnKeyType 数据类型,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57029336/

相关文章:

angular - 将查询参数与 @ngrx/router-store 合并

typescript - 如何在 typescript 的 webpack 中使用 seznam mapy?

jquery - 无法将 jQuery 添加到角度 cli 项目

javascript - 从 React Native 导入 StyleSheet 时未定义不是对象

javascript - react Hello World 问题

javascript - 当您重新访问 react native 屏幕时如何重新运行方法?

ios - Apple Mach Linker 未找到,缺少依赖 React

node.js - 如何处理 puppeteer 中按钮单击的新页面?

javascript - Uncaught TypeError : this. 函数不是函数

react-native - 如何在 React Native 中加载 Google Places API?