首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >使用TS设置RN中的类型

使用TS设置RN中的类型
EN

Stack Overflow用户
提问于 2019-07-15 12:21:02
回答 1查看 51关注 0票数 2

在我的RN应用程序中,我有以下接口。

代码语言:javascript
复制
interface IProps extends Props<IProps> {
  label?: string;
  editable?: boolean;
  maxLength?: number;
  autoCorrect?: boolean;
  placeholder?: string;
  // tslint:disable-next-line: max-line-length
  autoCapitalize?: 'none' | 'sentences' | 'words' | 'characters' | undefined;
  // tslint:disable-next-line: max-line-length
  returnKeyType?: 'none' | 'done' | 'search' | 'default' | 'go' | 'next' | 'send' | 'previous' | 'google' | 'join' | 'route' | 'yahoo' | 'emergency-call';
  // tslint:disable-next-line: max-line-length
  keyboardType?: 'default' | 'email-address' | 'numeric' | 'phone-pad' | 'visible-password' | 'ascii-capable' | 'numbers-and-punctuation' | 'url' | 'number-pad' | 'name-phone-pad' | 'decimal-pad' | 'twitter' | 'web-search' | undefined;
  secureTextEntry?: boolean;
  inputStyle?: object;
  containerStyle?: object;
  inputContainerStyle?: object;
}

这里的枚举,returnKeyType类型是一个枚举。在这里定义整个枚举似乎很难看。有没有更好的方法?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2019-07-15 12:35:43

试试这个:

代码语言:javascript
复制
enum AutoCapitalize {
  NONE = 'none',
  SENTENCES = 'sentences',
  WORDS = 'words',
  CHARACTERS = 'characters',
  UNDEFINED = '',
}

enum ReturnKeyType {
  ...
}

interface IProps extends Props<IProps> {
  label?: string;
  editable?: boolean;
  maxLength?: number;
  autoCorrect?: boolean;
  placeholder?: string;
  // tslint:disable-next-line: max-line-length
  autoCapitalize?: AutoCapitalize;
  ...
}
票数 3
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/57033224

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档